【问题标题】:Using a custom variable in a 3rd party jQuery plugin在第三方 jQuery 插件中使用自定义变量
【发布时间】:2012-08-18 01:51:31
【问题描述】:

我不太擅长编写 jQuery,但请原谅这个幼稚的问题:

我希望将单击的 href 值放入“backstretch”jQ 插件中。 (http://srobbin.com/jquery-plugins/jquery-backstretch/)

我的代码如下所示:

$(function() {

    var bgImage = $('.active').attr("href"); //gets the value of the href on the a with the class 'active' and puts it in a variable.


    $('.clicks a').click(function() {
        $('.clicks a').removeClass('active');
        $(this).addClass('active');
        return false;
    }) //removes all 'active' classes, and puts the 'active' class on the clicked a tag.


    $.backstretch("bgImage", {speed: 150}); // uses the value the variable in this plugin.

}); //end.ready

但它不起作用,有什么想法吗?提前致谢!

【问题讨论】:

  • 至少你写的是$(function() {而不是jQuery(document).ready(function() {。天哪,当我看到它时,我讨厌。

标签: jquery variables jquery-plugins


【解决方案1】:

好的,我明白了。如果有人想知道,我就是这样做的:

$(function() {
  $.backstretch("<?php bloginfo('template_url'); ?>/images/tn_bg2.jpg", {speed: 150});
  $('.clicks a').click(function() {
    var happy = $(this).attr('href');
      $(this).fadeIn('slow', function() {
        $("#backstretch img").attr("src", happy);

      });
      return false;
  });
}); //end.ready

【讨论】:

    猜你喜欢
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 2018-01-14
    • 1970-01-01
    相关资源
    最近更新 更多