on mouse enter slide from left to right background position with jQuery - javascript

I have a button for which I want to slide his background from #000 to #ccc.
My problem is how to do that slide transition of button background on hover or mouseenter.
It is possible to do this with jQuery?
Very important , I don' want to use background images so all suggestions about images ..skip pls.
This is an annoying fiddle created only with css but is working only from top to bottom and not from left to right how I need.
http://jsfiddle.net/xu3ck/166/
Submit Form
.btn {
width: 180px;
text-decoration: none;
height: 40px;
border-radius: 10px;
text-align: center;
color: white;
line-height: 40px;
font-size: 20px;
font-family: arial, sans-serif;
margin: 20px;
float: left;
display: block;
color: white;
box-shadow: rgba(0,0,0,0.3) 1px 1px 3px inset;
}
.two {
background: linear-gradient(#111, #eee);
background-repeat: repeat;
background-size: 100% 200%;
transition: all .5s linear;
}
.two:hover, .two:focus, .two:active {
background-position: 0 -200%;
}
ty.

What the example does is it creates a liniar background on the button which spans 200% of the buttons height. When your mouse goes over the button it moves the background 200% up.
What I changed, is I changed the gradient from "top to bottom" to "left to right". Set the width 200% instead of the height, and on the hover I set the background 200% to the right.
I fixed it in this JsFiddle
What I changed was the following:
background: linear-gradient(#111, #eee);
To
background: linear-gradient(to right, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);
background-size: 100% 200%;
To
background-size: 200% 100%;
And
background-position: 0 -200%;
To
background-position: -200% 0;

You can make it work with :before and :after pseudoelements, which are compatible with IE8. No need for jQuery. Just CSS.
See this demo here.

Related

How to Make Pop-Up Title Card on Hover?

So for my website, I have a portfolio page and I want to design a simple image thumbnail for my Google doc or Word documents to link essays and stuff. The same for PDFs, Slides, etc.
I want the logo or letter to be shown and when you hover on it, I want a title card to "pop" up and like bounce up a bit and then when you hover off, I want the card to slide down and disappear.
In theory, this is what I want it to look like:
Whether it just slides up and then slides down or shoots up, bounces like it's hitting the bottom of the square, then falls down, doesn't matter - I'm just wondering how to do this.
There are a ton of different ways to do this.
Here is a CSS only way.
Basically, you would create a different class name for each title card that you want to have a hover pop-up caption. I use a pseudo selector for the content in the hover pop up.
Hope this helps!
.title-card {
position: relative;
display: inline-block;
width: 200px;
height: 200px;
margin: 5px;
background: #e8e8e8;
border: 1px solid #fff;
box-shadow: 1px 1px 3px 0px rgba(0,0,0,0.38);
border-radius: 6px;
color: black;
padding: 10px;
overflow: hidden;
background-repeat: no-repeat;
background-position: 50% 50%;
font-family: Arial, sans-serif;
}
.title-card::before {
position: absolute;
display: inline-block;
left: 0;
width: 100%;
height: 50%;
padding: 10px;
background: -moz-linear-gradient(top, rgba(0,0,0,0.53) 0%, rgba(0,0,0,0.24) 100%);
background: -webkit-linear-gradient(top, rgba(0,0,0,0.53) 0%,rgba(0,0,0,0.24) 100%);
background: linear-gradient(to bottom, rgba(0,0,0,0.53) 0%,rgba(0,0,0,0.24) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#87000000', endColorstr='#3d000000',GradientType=0 );
color: #fff;
overflow-x: hidden;
overflow-y: auto;
opacity: 0;
transform: translateY(200%);
transition: all 500ms ease;
}
.title-card:hover::before {
opacity: 1;
transform: translateY(100%);
}
.title-card.caption-a::before {
content: "Hello from the other side!";
}
.title-card.caption-b::before {
content: "It's tricky!";
}
.title-card.caption-c::before {
content: "Don't call it a comeback!";
}
.title-card.logo-a {
background-image: url(https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a);
}
.title-card.logo-b {
background-image: url(https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/se/se-icon.png?v=93426798a1d4);
}
.title-card.logo-c {
background-image: url(https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/sf/sf-icon.png?v=6c3100d858bb);
}
.title-card.logo-d {
background-image: url(https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/su/su-icon.png?v=0ad5b7a83e49);
}
<div class="title-card logo-a caption-a">I have a caption, hover over me!</div>
<div class="title-card logo-b caption-b">I have a caption, hover over me!</div>
<div class="title-card logo-c caption-c">I have a caption, hover over me!</div>
<div class="title-card logo-d">I don't have a hover caption :(</div>

Textarea with alternate rows and line numbers

I'm trying to draw a textarea with alternate rows and line numbers.
A very simple solution to have line numbers is the following - see here for more details.
textarea {
background: url(http://i.imgur.com/2cOaJ.png);
background-attachment: local;
background-repeat: no-repeat;
padding-left: 35px;
padding-top: 10px;
border-color: #ccc;
}
<textarea rows="10" cols="40"></textarea>
While to have a textarea with alternate rows is just a simple as
textarea {
background-image: linear-gradient(#F1F1F1 50%, #F9F9F9 50%);
background-size: 100% 4rem;
border: 1px solid #CCC;
width: 100%;
height: 400px;
line-height: 2rem;
margin: 0 auto;
padding: 4px 8px;
}
<textarea rows="10" cols="40"></textarea>
Both solutions works ok, but combining them it's tricky since both makes use of the background to hack the line numbers and the alternate rows background.
You could combine them by wrapping your textarea in a div then assign the stripped background styles to that wrapping div, so the 2 backgrounds are like layered.
textarea {
background: url(http://i.imgur.com/2cOaJ.png);
background-attachment: local;
background-repeat: no-repeat;
padding-left: 35px;
padding-top: 10px;
border-color: #ccc;
font-size: 13px;
line-height: 16px;
}
.textarea-wrapper {
display: inline-block;
background-image: linear-gradient(#F1F1F1 50%, #F9F9F9 50%);
background-size: 100% 32px;
background-position: left 10px;
}
<div class="textarea-wrapper">
<textarea rows="10" cols="40"></textarea>
</div>
The wrapping div I set to display: inline-block so it wraps the textarea like an inline element and I positioned the background gradient 10px from the top to account for you padding-top.
You may have to play with the background size of the gradient to get it to properly match the line-height of the textarea.
UPDATE
To #DavidThomas's point, to help line up your text with the alternating gradient the background-size height value should be 2 times the line-height of the textarea (see updated snippet). But the harder thing is to make it line up with the image numbers.
You could use multiple backgrounds for the same element.
CSS allows you to add multiple background images for an element, through the background-image property.
In you case:
textarea {
width: 100%;
min-height: 100px;
background: url(http://i.imgur.com/2cOaJ.png) top -12px left / auto no-repeat,
linear-gradient(#F1F1F1 50%, #F9F9F9 50%) top left / 100% 32px;
border: 1px solid #CCC;
box-sizing: border-box;
padding: 0 0 0 30px;
resize: vertical;
line-height: 16px;
font-size: 13px;
}
body {
margin: 0;
}
<textarea rows="10" cols="40"></textarea>

Create a background transition in a row

I have a row with two blocks inside in which a background image opens in the row when a picture is passed on.
Unfortunately I can not change the html code much while I can change it with css.
So when I go to the internal image, the hover class is added to the line.
I would like the background to somehow have a transition.
For now it only takes one shot and I can not change it.
this is my css:
#rowContattaci {
background: black;
padding-left: 0px !important;
padding-right: 30% !important;
transition: 1s;
min-height:100px;
margin-left: 0% !important;
left: 0px !important;
}
#rowContattaci.hover {
background: url("https://onaliternote.files.wordpress.com/2016/11/wp-1480230666843.jpg?crop");
transition: 2s !important;
}
<div id="rowContattaci" data-vc-full-width="true" data-vc-full-width-init="true" class="vc_row wpb_row vc_row-fluid eightRow sectionContattaci rowHome section" style="position: relative; left: -231.094px; box-sizing: border-box; width: 1920px; padding-left: 231.094px; padding-right: 242.906px;"></div>
It looks like a typo. Useful ref: CSS :hover Selector
Anyway change #rowContattaci.hover to #rowContattaci:hover to resolve your issue.
Update Snippet:
#rowContattaci {
background: black;
padding-left: 0px !important;
padding-right: 30% !important;
transition: 1s;
min-height:100px;
margin-left: 0% !important;
left: 0px !important;
}
#rowContattaci:hover {
background: url("https://onaliternote.files.wordpress.com/2016/11/wp-1480230666843.jpg?crop");
transition: 2s !important;
}
<div id="rowContattaci" data-vc-full-width="true" data-vc-full-width-init="true" class="vc_row wpb_row vc_row-fluid eightRow sectionContattaci rowHome section" style="position: relative; left: -231.094px; box-sizing: border-box; width: 1920px; padding-left: 231.094px; padding-right: 242.906px;"></div>
P.S. My suggestions:
1) Keep all your styles together i.e. to not keep half of your styles inline and half external.
2) Avoid using !important everywhere.
There's a couple things you need to change to get your example to work:
As others have mentioned, there's a typo with your css hover style - it should be :hover not .hover
You need to apply some positioning and sizing on your background image otherwise, you only see the top left of the image, which also happens to be black, so it looks like it just flashes but does not show the logo.
Tips: I would also second thebrownkid's recommendation that you separate your css styles rather than writing in-line css. The example below removes all the unnecessary styles.
#rowContattaci {
background-color: black;
padding-right: 30%;
min-height: 100px;
}
#rowContattaci:hover {
background-color: transparent;
background-image: url("https://onaliternote.files.wordpress.com/2016/11/wp-1480230666843.jpg?crop");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
transition: 1s;
}
<div id="rowContattaci"></div>
You couldn't make your background picture blend in a transition. However you could use a trick with 2 divs one on top of the other. The bottom one will always have a background image, the top one will change color from transparent to black in transition.
All you have to do is to align the elements properly.
#rowContattaci {
background-color: black;
background-image: none;
transition: 1s;
min-height:100px;
margin-left: 0% !important;
left: 0px !important;
margin: 0;
}
#rowContattaci:hover {
background-color: transparent;
}
#rowContattaciBack {
background-image: url("https://onaliternote.files.wordpress.com/2016/11/wp-1480230666843.jpg?crop");
background-size: 300px;
}
<div id="rowContattaciBack" style="position: relative; left: -231.094px; box-sizing: border-box; width: 1920px; padding-left: 231.094px; padding-right: 242.906px; margin:0;">
<div id="rowContattaci" data-vc-full-width="true" data-vc-full-width-init="true" class="vc_row wpb_row vc_row-fluid eightRow sectionContattaci rowHome section">
</div>
</div>

Unable to show color fill animation in div when the page loads

$("#whoami").waypoint(function() {
console.log('you have scrolled to the h1!');
});
.d8{
border: 1px solid black;
width: 100%;
height: 2.5rem;
margin-left: 5rem;
border-radius: 1rem;
background: linear-gradient(to right, #e74c3c 85%, #FFF 50%);
}
<div class="d8"></div>
Now I have been trying to fill the color in the div when the waypoint reaches the particular section having some nice animation effect for the user and I am not able to achieve it though,
Have tried transition effect and keyframe none seems to work, any help would be very much appreciated.
In you case you can animate background-size instead of background-image (that you cannot animate) and make the linear-gradient to be one color as the white part will be the part without background:
.d8 {
border: 1px solid black;
width: 80%;
height: 2.5rem;
margin-left: 5rem;
border-radius: 1rem;
background-image: linear-gradient(to right, #e74c3c, #e74c3c);
background-size: 80% 100%;
background-repeat: no-repeat;
transition: 0.5s;
}
.d8:hover {
background-size: 100% 100%;
}
<div class="d8"></div>

transparent UI box in CSS

I'm trying to make a transparent glass-like box, something similar to what is shown in this image:
I don't know whats wrong with my CSS because it looks like a white box (with low opacity) shown, basically it doesn't have the look or feel as shown in the picture. I was wondering if anyone knows how to achieve something like this?
My CSS (I tried a couple of things like blur or opacity but neither one yields the result I want):
.body-bg-color{
background: #00467F;
background: -webkit-linear-gradient(to right, #A5CC82, #00467F);
background: linear-gradient(to right, #A5CC82, #00467F);
}
div.glass-bg-color::before {
z-index: -1;
content: ' ';
width: 100%;
height: 100%;
position: absolute;
// filter: blur(4px);
// box-shadow: inset 0 0 0 3000px rgba(255,255,255,0.3);
opacity: 0.3;
background-color: rgba(255,255,255, 1);
}
.glass-bg-color {
color: white;
position: relative;
}
<div class="body-bg-color">
<div class="glass-bg-color">
Foo
</div>
<div class="glass-bg-color">
Bar
</div>
<div class="glass-bg-color">
Baz
</div>
</div>
The example you've shown uses a radial gradient as the background of the underlying element, and transparent white for the "glass" effect. For example I've created an elliptical background gradient ( by modifying an example on MDN) placed as a transparent image on top of a solid background of the body.
The glass effect is now just a transparent white background on a container element. I've used an inline-block for demonstration:
body {
margin: 0px;
width: 100vw;
height;: 100vh;
background-color: #00467F;
background-image:
radial-gradient(ellipse farthest-corner at 80vw 15vh ,
rgba( 250, 240, 128, 0.5) 5%, rgba( 250,240,128,0) 95%
);
background-attachment:fixed;
}
.glass {
background-color: rgba( 255,255, 255, 0.1); /* transparent white */
color:white;
display:inline-block;
border-radius: 15px;
padding: 10px;
}
<div class="glass"
style="margin-left:50vw; margin-top: 20vh; width: 80px; height: 180px;">
Hello Folks!
</div>
(Note the CSS for the body background can produce unwanted scrollbars if the body margin is non zero. An alternative to zero width body margins may be to create a fixed position background element with a z-index of -1. Previous discussion of the issue may be found at CSS3 gradient background set on body doesn't stretch but instead repeats? which I have already found useful.
The answer is really just applying white with a low opacity on the box backgrounds:
The CSS:
body {
position: relative;
width: 100%;
background: #00467F;
background: -webkit-linear-gradient(left, #A5CC82, #00467F);
background: -moz-linear-gradient(left, #A5CC82, #00467F);
background: -o-linear-gradient(left, #A5CC82, #00467F);
background: linear-gradient(to right, #A5CC82, #00467F);
}
.glass-bg-color {
position: relative;
display: inline-block;
float: left;
margin: 20px;
width: 200px;
height: 200px;
border-radius: 4px;
text-align: center;
background-color: rgba(255,255,255,.08);
color: white;
}
The HTML:
`
<div class="glass-bg-color">
Foo
</div>
<div class="glass-bg-color">
Bar
</div>
<div class="glass-bg-color">
Baz
</div>
`
See the fiddle here: https://jsfiddle.net/4y8bx2eg/
Your current background opacity is set to 1. It should be closer to 0.2. And your spread-radius of the box-shadow is 3000px, which should be set more relative to the size of your elements, I'd also suggest changing the blur-radius a bit, which is currently zero.
Is this more like what you are looking for?
.body-bg-color{
background: #00467F;
background: -webkit-linear-gradient(to right, #A5CC82, #00467F);
background: linear-gradient(to right, #A5CC82, #00467F);
text-align: center;
}
.glass-bg-color {
box-shadow: inset 0 0 50px 10px rgba(255,255,255,0.2);
background-color: rgba(255,255,255, 0.2);
color: white;
position: relative;
display: inline-block;
padding: 10em;
}

Categories

Resources