English 中文(简体)
页: 1 学历 URL hash
原标题:jQuery scrollTop if URL has hash

我写了这一简单图象,它使浏览器窗户顺利发展,使散列车与URL连接起来。

$.fn.extend({
    scrollWindow: function(options) {
        var defaults = { duration: "slow", easing : "swing" }                 
        var options =  $.extend(defaults, options);
        return this.each(function() {             
            $(this).click(function(e) {
                var target = $(this).attr( href );
                $( html,body ).animate({scrollTop: $(target).offset().top}, options.duration, options.easing, function() {
                    location.hash = target;
                });
                e.preventDefault();
            });

        });
    }
});

我如何扩大这一缩略语,这样,如果电离层的电离层在电离层中存在一 has,它就能够把电流放到该页的那部分?

我有一半人理解如何通过使用<代码>window. 所在地.hash来做到这一点,尽管我不清楚在什么地方最好在原始案文中添加这一点。

最佳回答

在一个单独的变量中储存这一功能,如果存在散射,则将其称为功能。 我已执行过你的请求,即现在的<代码> 所在地.hash每次均使用<代码>$.scrollWindow<>。 其他执行也遵循同样的原则。

$.fn.extend({
    scrollWindow: function(options) {
        var defaults = { duration: "slow", easing : "swing" }                 
        var options =  $.extend(defaults, options);
        var goToHash = function(target){
            $( html,body ).animate({scrollTop: $(target).offset().top}, options.duration, options.easing, function() {
                location.hash = target;
            });
        };
        if(location.hash.length > 1) goToHash(location.hash);
        return this.each(function() {             
            $(this).click(function(e) {
                //Remove junk before the hash if the hash exists:
                var target = $(this).attr( href ).replace( ^([^#]+)# , # );
                goToHash(target);
                e.preventDefault();
            });

        });
    }
});
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签