I have a problem with a website. I am new in javascript. I need to do that when I click on a menu item (wordpress) and then whe window is loaded, automaticaly scroll down to the content(empty) div. My javascript code not working. What should I do?
My code:
<script>
$(".menu-item").click(function() {
$( window ).load(function() {
$('html, body').animate({ scrollTop: $('.content').offset().top }, 'slow');
});
});
</script>
The two codes working with alone, but in this version not working.
I do not know what you exactly want, but first you need to call window.onload and then append click event.
Like this:
<script>
$( window ).load(function() {
$(".menu-item").click(function() {
$('html, body').animate({ scrollTop: $('.content').offset().top }, 'slow');
});
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.