How to add image when img tag is less than 100 from top using 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
 |Â
show 1 more comment
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
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
6701626
6701626
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
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid â¦
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid â¦
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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