开始的条件函数:Ariel Flesler 的 SerialScroll 中的设置

发布于 2024-08-13 10:02:44 字数 791 浏览 6 评论 0原文

站点位于@beattrainsoundsystem.com/home

我正在使用serialScroll 为许多包含舞蹈角色的div 制作动画,并使用LocalScroll 为内容div 制作动画。我的问题是,当您尝试加载带有哈希值的 URL(例如beattrainsoundsystem.com/home#store)时,角色 div 不会动画到正确的位置。我知道要实现这一点,我需要为“start:”设置创建一个条件函数,以根据 URL 中的哈希值更改“start:”值。作为 jQuery 的新手,我不太确定如何编写此代码。

我已经在使用 URI 解析器插件来返回 URL 中的哈希值,因此对于“http:// www.beattrainsoundsystem.com/home#store

var urlHash = $.url.attr('anchor');

将返回“store”

所以我需要的是一个函数,它说:

if (urlHash == home) {
     var start = 0
} else if (urlHash == mixes) {
     var start = 1,
} else if (urlHash == contact) {
     var start = 2,
}

这显然没有正确编码,但它是我需要使此工作的脚本的概念化。

感谢您的帮助!

Site is Located @ beattrainsoundsystem.com/home

I'm using serialScroll to animate a number of divs containing dancing characters, and using LocalScroll to animate the content divs. My issue is that when you try and load a URL with a hash ( for example beattrainsoundsystem.com/home#store) the character divs do not animate to the correct position. I know that to make this happen, I need to create a conditional function for the "start:" setting, to change the "start:" value depending on the hash in the URL. As somewhat of a novice at jQuery, I'm not exactly sure how to code this.

I'm already using a URI parser plugin to return the hash in the URL, so for "http://www.beattrainsoundsystem.com/home#store"

var urlHash = $.url.attr('anchor');

will return "store"

So what I need is a function that says:

if (urlHash == home) {
     var start = 0
} else if (urlHash == mixes) {
     var start = 1,
} else if (urlHash == contact) {
     var start = 2,
}

This is obviously not coded correctly, but is a conceptualization of the script that I need to make this work.

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

本宫微胖 2024-08-20 10:02:44

您可能应该将其与 localScroll 集成。如果调用$.localScroll.hash(),它将滚动到哈希指向的元素,并将更改通知serialScroll。

You should probably integrate this with localScroll. If you call $.localScroll.hash(), it will scroll to the element pointed by the hash and notify the change to serialScroll.

我做我的改变 2024-08-20 10:02:44

它并没有直接跳到我身上,我试图找到顶部链接的点击事件正在处理的地方,所以我可以给出一个具体的例子。

看起来动画不起作用的唯一一次是当我直接转到 URL 中包含哈希值的某个页面时。因此,我可能会这样做:

  1. 在页面加载时,从 URL 中获取 #name
  2. 查找其 href = 我获取的名称的元素(您将它们命名为相同,最好是给这些 一个 id,例如
  3. 在该元素上执行 click() 事件以模拟正常动画方法

如果您希望它加载到正确的位置而不显示动画,那么这并不理想

您应该能够执行以下操作:

$(document).ready(function(){
      // This whole part is pseudocode since I didn't spend
      // the time to find exactly how you're doing things

      // get the hash portion from the URL
      // (just copying you here, haven't done this myself)
      var sourceLinkHref = $.url.attr('anchor');

      // Find the <a> tag whose href attribute matches the
      // name you just found, and .click() it
      $("a[href=#" + sourceLinkHref + "]")
          .click();
   });

It doesn't jump right out at me where the click events for the links at the top are being handled which I was trying to find so I could give a specific example.

It looks like the only time the animation doesn't work is when I go directly to some page that has the hash in the URL. So, I might do something like:

  1. On page load, grab the #name from the URL
  2. Find the element whose href = the name I grabbed (you have them named identically, better would be to give those <a href="#name"> an id such as <a id="name" href="#name">
  3. Do a click() event on that element to simulate the normal animation method

This isn't ideal if you want it to load in the correct position without showing an animation.

You should be able to do something like this:

$(document).ready(function(){
      // This whole part is pseudocode since I didn't spend
      // the time to find exactly how you're doing things

      // get the hash portion from the URL
      // (just copying you here, haven't done this myself)
      var sourceLinkHref = $.url.attr('anchor');

      // Find the <a> tag whose href attribute matches the
      // name you just found, and .click() it
      $("a[href=#" + sourceLinkHref + "]")
          .click();
   });
巴黎盛开的樱花 2024-08-20 10:02:44
jQuery(function( $ ){
var urlHash = $.url.attr('anchor');
if (urlHash=="mixes") {
    $("#sectionsContent").scrollTo( $("#mixes"), 0 );
    $("#sectionsMid").scrollTo( $("#mixmid"), 0 );
    $("#sectionsTop").scrollTo( $("#mixTop"), 0 );
    $("#sectionsBottom").scrollTo( $("#mixBottom"), 0 );
}

if (urlHash=="contact") {
    $("#sectionsContent").scrollTo( $("#contact"), 0 );
    $("#sectionsMid").scrollTo( $("#storemid"), 0 );
    $("#sectionsTop").scrollTo( $("#storeTop"), 0 );
    $("#sectionsBottom").scrollTo( $("#storeBottom"), 0 );
}

if (urlHash=="store") {
    $("#sectionsContent").scrollTo( $("#store"), 0 );
    $("#sectionsMid").scrollTo( $("#blogmid"), 0 );
    $("#sectionsTop").scrollTo( $("#blogTop"), 0 );
    $("#sectionsBottom").scrollTo( $("#blogBottom"), 0 );
}

});

jQuery(function( $ ){
var urlHash = $.url.attr('anchor');
if (urlHash=="mixes") {
    $("#sectionsContent").scrollTo( $("#mixes"), 0 );
    $("#sectionsMid").scrollTo( $("#mixmid"), 0 );
    $("#sectionsTop").scrollTo( $("#mixTop"), 0 );
    $("#sectionsBottom").scrollTo( $("#mixBottom"), 0 );
}

if (urlHash=="contact") {
    $("#sectionsContent").scrollTo( $("#contact"), 0 );
    $("#sectionsMid").scrollTo( $("#storemid"), 0 );
    $("#sectionsTop").scrollTo( $("#storeTop"), 0 );
    $("#sectionsBottom").scrollTo( $("#storeBottom"), 0 );
}

if (urlHash=="store") {
    $("#sectionsContent").scrollTo( $("#store"), 0 );
    $("#sectionsMid").scrollTo( $("#blogmid"), 0 );
    $("#sectionsTop").scrollTo( $("#blogTop"), 0 );
    $("#sectionsBottom").scrollTo( $("#blogBottom"), 0 );
}

});

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文