简体   繁体   中英

animate only div instead of whole page when clicking on link in query

I developing a site using jQuery, CSS and HTML. The page has on the left side a static menu which should always be shown and a content div. When I press a link in the menu right now, the whole page animates and slides to left revealing the div which the menu element links to using href. I would very much like to modify this so only the content div animates and is replaced. Is this possible?

Regards

Yes, this is possible. Without some code there is not much more I can give you. This is as generic as I can get:

$(".menuLink").click(function() {
    var linkedContent = ...identify the content being moved into view...
    var currentContent = ...identify the content being moved from view...

    var moveOldTo = "-=" + currentContent.width() + "px";
    //assuming your content divs are relatively positioned
    currentContent.animate({ left: moveOldTo }, 1000);

    var moveNewTo = "-=" + linkedContent.width() + "px";
    linkedContent.animate({ left: moveNewTo }, 1000);
});

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM