How to add image when img tag is less than 100 from top using jquery?
up vote
0
down vote
favorite
I want to add an image when the user scrolling down and mdl-grid is less than 100 from top.
Here is my html
<div class="mdl-grid mdl-shadow--2dp" style="margin-top:4px;">
<div class="mdl-cell mdl-cell--3-col-desktop mdl-cell--3-col-tablet mdl-cell--1-col-phone div-mobile">
<div class="image-div" style="height:200px;width:200px;">
<img class="image-tag" src="" style="height:200px;width:98px;" />
</div>
</div>
Jquery
$(window).scroll(function ()
$('.mdl-grid').each(function ()
var offsetTopPosition = $(this).offset().top - $(window).scrollTop();
if (offsetTopPosition < 100)
$(this).find('img').attr('src', '/rec.jpeg');
);
);
</div>
jquery
|
show 1 more comment
up vote
0
down vote
favorite
I want to add an image when the user scrolling down and mdl-grid is less than 100 from top.
Here is my html
<div class="mdl-grid mdl-shadow--2dp" style="margin-top:4px;">
<div class="mdl-cell mdl-cell--3-col-desktop mdl-cell--3-col-tablet mdl-cell--1-col-phone div-mobile">
<div class="image-div" style="height:200px;width:200px;">
<img class="image-tag" src="" style="height:200px;width:98px;" />
</div>
</div>
Jquery
$(window).scroll(function ()
$('.mdl-grid').each(function ()
var offsetTopPosition = $(this).offset().top - $(window).scrollTop();
if (offsetTopPosition < 100)
$(this).find('img').attr('src', '/rec.jpeg');
);
);
</div>
jquery
So what's wrong with your code?
– Justinas
Nov 10 at 20:48
@Justinas it's not set the image when I scroll down
– Liam neesan
Nov 10 at 20:50
I think @Justinas was looking for more detail - do you see any errors in the console; if you put logging statements in the function, can you confirm youroffsetTopPosition
is being calculated as you expect, that you ever get into yourif()
condition, etc?
– Stevangelista
Nov 11 at 0:23
It work jsfiddle.net/mroj1ud5
– Mohammad
Nov 11 at 8:20
@Mohammad Sorry for delay. I saw that fiddle it is working there. But in mine it is not working
– Liam neesan
Nov 12 at 17:22
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to add an image when the user scrolling down and mdl-grid is less than 100 from top.
Here is my html
<div class="mdl-grid mdl-shadow--2dp" style="margin-top:4px;">
<div class="mdl-cell mdl-cell--3-col-desktop mdl-cell--3-col-tablet mdl-cell--1-col-phone div-mobile">
<div class="image-div" style="height:200px;width:200px;">
<img class="image-tag" src="" style="height:200px;width:98px;" />
</div>
</div>
Jquery
$(window).scroll(function ()
$('.mdl-grid').each(function ()
var offsetTopPosition = $(this).offset().top - $(window).scrollTop();
if (offsetTopPosition < 100)
$(this).find('img').attr('src', '/rec.jpeg');
);
);
</div>
jquery
I want to add an image when the user scrolling down and mdl-grid is less than 100 from top.
Here is my html
<div class="mdl-grid mdl-shadow--2dp" style="margin-top:4px;">
<div class="mdl-cell mdl-cell--3-col-desktop mdl-cell--3-col-tablet mdl-cell--1-col-phone div-mobile">
<div class="image-div" style="height:200px;width:200px;">
<img class="image-tag" src="" style="height:200px;width:98px;" />
</div>
</div>
Jquery
$(window).scroll(function ()
$('.mdl-grid').each(function ()
var offsetTopPosition = $(this).offset().top - $(window).scrollTop();
if (offsetTopPosition < 100)
$(this).find('img').attr('src', '/rec.jpeg');
);
);
</div>
jquery
jquery
asked Nov 10 at 20:41
Liam neesan
6531525
6531525
So what's wrong with your code?
– Justinas
Nov 10 at 20:48
@Justinas it's not set the image when I scroll down
– Liam neesan
Nov 10 at 20:50
I think @Justinas was looking for more detail - do you see any errors in the console; if you put logging statements in the function, can you confirm youroffsetTopPosition
is being calculated as you expect, that you ever get into yourif()
condition, etc?
– Stevangelista
Nov 11 at 0:23
It work jsfiddle.net/mroj1ud5
– Mohammad
Nov 11 at 8:20
@Mohammad Sorry for delay. I saw that fiddle it is working there. But in mine it is not working
– Liam neesan
Nov 12 at 17:22
|
show 1 more comment
So what's wrong with your code?
– Justinas
Nov 10 at 20:48
@Justinas it's not set the image when I scroll down
– Liam neesan
Nov 10 at 20:50
I think @Justinas was looking for more detail - do you see any errors in the console; if you put logging statements in the function, can you confirm youroffsetTopPosition
is being calculated as you expect, that you ever get into yourif()
condition, etc?
– Stevangelista
Nov 11 at 0:23
It work jsfiddle.net/mroj1ud5
– Mohammad
Nov 11 at 8:20
@Mohammad Sorry for delay. I saw that fiddle it is working there. But in mine it is not working
– Liam neesan
Nov 12 at 17:22
So what's wrong with your code?
– Justinas
Nov 10 at 20:48
So what's wrong with your code?
– Justinas
Nov 10 at 20:48
@Justinas it's not set the image when I scroll down
– Liam neesan
Nov 10 at 20:50
@Justinas it's not set the image when I scroll down
– Liam neesan
Nov 10 at 20:50
I think @Justinas was looking for more detail - do you see any errors in the console; if you put logging statements in the function, can you confirm your
offsetTopPosition
is being calculated as you expect, that you ever get into your if()
condition, etc?– Stevangelista
Nov 11 at 0:23
I think @Justinas was looking for more detail - do you see any errors in the console; if you put logging statements in the function, can you confirm your
offsetTopPosition
is being calculated as you expect, that you ever get into your if()
condition, etc?– Stevangelista
Nov 11 at 0:23
It work jsfiddle.net/mroj1ud5
– Mohammad
Nov 11 at 8:20
It work jsfiddle.net/mroj1ud5
– Mohammad
Nov 11 at 8:20
@Mohammad Sorry for delay. I saw that fiddle it is working there. But in mine it is not working
– Liam neesan
Nov 12 at 17:22
@Mohammad Sorry for delay. I saw that fiddle it is working there. But in mine it is not working
– Liam neesan
Nov 12 at 17:22
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243211%2fhow-to-add-image-when-img-tag-is-less-than-100-from-top-using-jquery%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
So what's wrong with your code?
– Justinas
Nov 10 at 20:48
@Justinas it's not set the image when I scroll down
– Liam neesan
Nov 10 at 20:50
I think @Justinas was looking for more detail - do you see any errors in the console; if you put logging statements in the function, can you confirm your
offsetTopPosition
is being calculated as you expect, that you ever get into yourif()
condition, etc?– Stevangelista
Nov 11 at 0:23
It work jsfiddle.net/mroj1ud5
– Mohammad
Nov 11 at 8:20
@Mohammad Sorry for delay. I saw that fiddle it is working there. But in mine it is not working
– Liam neesan
Nov 12 at 17:22