0

我正在使用 bootstrap 中的 scrollpsy。

我举了一个例子来说明我正在尝试做的事情:

http://jsfiddle.net/te3V4/15/

一切都很好,他在每个部分 id 传递一个活动类li,但我想在每个部分的标题处更改背景

例如:

如果#studio background-color: #0915ff;
如果#green background-color: 085606;

$(function() {
  var $spy = $('.nav');
  $spy.bind("activate", function(e) {
    //e.target is the current <li> element
    var header = $(e.target).find("a").attr("href");
        alert (header);
        $studio = $('#studio')
        $duplex = $('#duplex')
        $tower = $('#tower')
        If( $(header) == "#studio" ) window.alert( “ALERT ACTIVED”);
  });
});
4

1 回答 1

0

我不熟悉 scrollspy,但我已经更新了你的小提琴http://jsfiddle.net/te3V4/18/

基本上在每个标签上,我都添加了一个“数据背景”属性,它是你想要的颜色值。我在运行时重置了所有颜色,并使用以下代码分配了正确的颜色。

   var $spy = $('.nav');
        var first = $('a', '#navbar')[0];
        $(first).css({'background-color':$(first).data('background')});
  $spy.bind("activate", function(e) {

  $('a', '#navbar').css({'background-color':'inherit'});
var header = $(e.target).find("a");//.attr("hr");
  $(header).css({'background-color': header.data('background')});
 });
于 2013-05-23T22:47:24.603 回答