如何保存生成的“div id”用户滚动时在屏幕上可见...并在用户加载页面时跳回到保存的div id [英] how to save the generated "div id " which are visible on screen when user scroll... and jump back to the saved div id..when user loads the page

查看:68
本文介绍了如何保存生成的“div id”用户滚动时在屏幕上可见...并在用户加载页面时跳回到保存的div id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用函数动态生成一些div id



i am generating some div id's dynamically using the function

generate: function(){


    $("#contenttext br ~ br").each(function(index,element) {

        $(this).after("<div id=\"bookmark-" + index + "\"></span>");

        var key= $('div[id^="bookmark-" ]');

        $('div:visible', key)


    });



    },




i want to save the visible div id when the page is scroll down ,and  
jump back or scroll back to the saved div id when the page is loaded, 


i am acheiving this by passing static div id (for example  #bookmark-65) in the below code , but i want to save the div id according to the scroll position and pass it back when page is reload ,same as saving cookie or local storage...but by using dynamically generated div id's

scroll:function()
{


    var container = $('div'),
        scrollTo = $('#bookmark-65');

    container.animate({
            scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop()

    });


any one help me..

推荐答案

#contenttext br~br)。each(function(index,element){
("#contenttext br ~ br").each(function(index,element) {


this )。after( < ; div id = \bookmark - + index + \>< / span>);

var key =
(this).after("<div id=\"bookmark-" + index + "\"></span>"); var key=


' div [id ^ =bookmark-]');


这篇关于如何保存生成的“div id”用户滚动时在屏幕上可见...并在用户加载页面时跳回到保存的div id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆