简体   繁体   中英

I want a div to scroll at the bottom of the page when the user scrolls

I can't use bootstrap for this i can use jquery

I have basic page with a container which has a button and some paragraph I want to move this at the bottom on the page when the user scrolls

Also this should only happen in a mobile view.

example: https://creditcards.chase.com/a1/marriottpremier/8TK?CELL=679Z&nck=120931994&ck=1213078&lk=1000160171

They used bootstrap

<div>
<h2>Near<h2>
<div>
<button>Learn more<button>
<p>conditions<p>
<div>

I have used jquery and media queries for this to work.

CSS
@media only screen and (max-width: 380px) {


    .fixed {
        bottom: 0;
        position: fixed;
        left: 0;
        width: 100%;
        max-width: 374px;
        margin: 0 auto;
        background-color: blue;
        height: 70px;

        }
    }


JQuery

<script>
jQuery(document).ready(function() {

// define variables
var navOffset, scrollPos = 0;

// add utility wrapper elements for positioning
jQuery("nav").wrap('<div class="button1"></div>');
jQuery("nav").wrapInner('<div class="inner"></div>');
jQuery(".nav-inner").wrapInner('<div class="inner-most"></div>');

// function to run on page load and window resize
function stickyUtility() {

// only update navOffset if it is not currently using fixed position
if (!jQuery("nav").hasClass("fixed")) {
navOffset = jQuery("nav").offset().top;
}

// apply matching height to nav wrapper div to avoid awkward content jumps
jQuery(".nav-placeholder").height(jQuery("nav").outerHeight());

} // end stickyUtility function

// run on page load
stickyUtility();

// run on window resize
jQuery(window).resize(function() {
stickyUtility();
});

// run on scroll event
jQuery(window).scroll(function() {

scrollPos = jQuery(window).scrollTop();

if (scrollPos >= navOffset) {
jQuery("nav").addClass("fixed");
} else {
jQuery("nav").removeClass("fixed");
}

});

});
</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.

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