Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [jQuery] Użycie styli zdefiniowanych w pliku CSS, Żeby został :hover po klikniąciu myszką
starach
post
Post #1





Grupa: Zarejestrowani
Postów: 999
Pomógł: 30
Dołączył: 14.01.2007
Skąd: wiesz ?

Ostrzeżenie: (0%)
-----


Jak w metodzie Fold.activate() mam pobrać styl :hover elementu <li> i przypisać go?
style.css
  1. body { background:rgb(255,153,51); }
  2. div#wrapper { width:90%; height:100px; margin:0 auto; background:rgb(255,204,0); }
  3. ul#menu { width:100%; list-style:none; background:white; }
  4. ul#menu li { float:left; padding:0 2em; }
  5. ul#menu li#link_1, ul#menu li#link_2, ul#menu li#link_3 { cursor:pointer; }
  6. ul#menu li#link_1 { background:rgb(255,80,80); }
  7. ul#menu li#link_2 { background:rgb(125,255,0); }
  8. ul#menu li#link_3 { background:rgb(0,125,190); }
  9. ul#menu li#link_1:hover, div#panels div#item_1 { background:rgb(255,100,100); }
  10. ul#menu li#link_2:hover, div#panels div#item_2 { background:rgb(165,255,40); }
  11. ul#menu li#link_3:hover, div#panels div#item_3 { background:rgb(20,145,190); }
  12.  
  13. div#panels { width:100%; }
  14. div#panels div { width:100%; display:none; }

index.htm
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  3. <title>Strona</title>
  4. <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
  5. <link rel="stylesheet" type="text/css" href="style/style.css" media="all" />
  6. <script type="text/javascript" src="script/jquery-1.2.6.js"></script>
  7. <script type="text/javascript" src="script/menu.js"></script>
  8. </head>
  9. <div id="wrapper">
  10. <ul id="menu">
  11. <li id="link_1">Pełne</li>
  12. <li id="link_2">Zakres</li>
  13. <li id="link_3">Filtry</li>
  14. </ul>
  15. <div id="panels">
  16. <div id="item_1"></div>
  17. <div id="item_2"></div>
  18. <div id="item_3"></div>
  19. </div>
  20. </div>
  21. </body>
  22. </html>

menu.js
( To jest javascript ale użyłem tagu PHP bo inne rozwalają wcięcia kodzie. )
  1. <?php
  2. function Fold_Collection($default)
  3. {
  4.    this.folds = new Array();
  5.    this.default_ = $default;
  6.    var ths = this;
  7.  
  8.    this.append = function($fold)
  9.    {
  10.        this.folds[this.folds.length] = $fold;
  11.    }
  12.    this.load = function()
  13.    {
  14.        var $links = $("ul#menu");
  15.        var $panels = $("div#panels");
  16.        $links.each(function($i)
  17.        {
  18.            $fold = new Fold($($links.get($i)), $($panels.get($i)), ths);
  19.            $fold.setEvtClick();
  20.            ths.append($fold);
  21.        });
  22.    }
  23.    this.deactivate = function()
  24.    {
  25.        for(var $i = 0; $i < this.folds.length; $i++)
  26.        {
  27.            this.folds[$i].deactivate();
  28.        }
  29.    }
  30.    this.init = function()
  31.    {
  32.        $("document").ready(
  33.        function()
  34.        {
  35.            ths.load();
  36.        });
  37.    }
  38. }
  39. function Fold($anch, $fold, $parent)
  40. {
  41.    this.anch_ = $anch;
  42.    this.fold_ = $fold;
  43.    this.parent_ = $parent;
  44.    this.setEvtClick = function()
  45.    {
  46.        this.anch_.click(
  47.        function()
  48.        {
  49.            this.parent_.deactivate();
  50.            this.activate();
  51.        });
  52.    }
  53.    this.activate = function()
  54.    {
  55.        
  56.    }
  57.    this.deactivate = function()
  58.    {
  59.        
  60.    }
  61. }
  62.  
  63. $folds = new Fold_Collection(0);
  64. $folds.init();
  65. ?>


Poradziłem sobie reorganizując style i dodając jedną klasę z takimi samymi ustawieniami jak :hover. Pobrać stylów dla :hover niestety nie zdołałem.
  1. ul#menu { width:100%; list-style:none; background:white; }
  2. ul#menu li { float:left; padding:0 2em; }
  3. li#link_1, li#link_2, li#link_3 { cursor:pointer; }
  4. li#link_1, div#item_1 { background:rgb(255,80,80); }
  5. li#link_2, div#item_2 { background:rgb(25,255,80); }
  6. li#link_3, div#item_3 { background:rgb(20,145,190); }
  7. li.link_active, li#link_1:hover, li#link_2:hover, li#link_3:hover
  8. { /*filter:alpha(opacity=100);*/ -moz-opacity:1; -khtml-opacity:1; /*opacity:1;*/ }
  9. li.link_inactive { /*filter:alpha(opacity=70);*/ -moz-opacity:0.7; -khtml-opacity:0.7; /*opacity:0.7;*/ }


  1. <ul id="menu">
  2. <li id="link_1" class="link_inactive">Zakres</li>
  3. <li id="link_2" class="link_inactive">Filtry</li>
  4. <li id="link_3" class="link_inactive">Aktulizacja</li>
  5. </ul>
  6. <div id="panels">
  7. <div id="item_1" class="item_inactive">
  8. (...)


Ten post edytował orglee 15.02.2009, 12:55:01
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 20:49