За последние 24 часа нас посетили 17635 программистов и 1723 робота. Сейчас ищут 887 программистов ...

оптимизироватьговнокод

Тема в разделе "JavaScript и AJAX", создана пользователем bookin, 20 окт 2011.

  1. bookin

    bookin Активный пользователь

    С нами с:
    11 ноя 2009
    Сообщения:
    120
    Симпатии:
    0
    прошу помощи в оптимизации кода, спер кружечки с google+ ток увеличение у них там на канвасе, а я сделал js, прошу знающих подсказать как его оптимизировать, заранее спасибо

    HTML:
    1. <!DOCTYPE HTML>
    2.  
    3.     <head>
    4.         <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    5.         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"  type="text/javascript"></script>
    6.  
    7.     <script type="text/javascript">
    8.         /**
    9.         * hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
    10.         * <http://cherne.net/brian/resources/jquery.hoverIntent.html>
    11.         *
    12.         * @param  f  onMouseOver function || An object with configuration options
    13.         * @param  g  onMouseOut function  || Nothing (use configuration options object)
    14.         * @author    Brian Cherne brian(at)cherne(dot)net
    15.         */
    16.         (function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);
    17.     </script>
    18.     <script type="text/javascript">
    19.         $(function(){
    20.             /*
    21.                drawCircle()
    22.                selector : селектор jQuery, который определяет элемент или массив элементов
    23.                center : центр окружности
    24.                radius : радиус окружности
    25.                angle: угол внутри окружности
    26.                x: смещение влево всех точек окружности
    27.                y: смещение по вертикали всех точек окружности
    28.  
    29.                Использование:
    30.                CSS: .box { background-color:red; height:90px; width:90px;  position:absolute; margin:5px;}
    31.                JS:drawCircle('.box', 50, 200, 90, 310, 220);
    32.             */
    33.                 function drawCircle(selector, center, radius, angle, x, y)
    34.                 {
    35.                 var total = $(selector).length;
    36.                 var alpha = Math.PI * 2 / total;
    37.                 $(selector).each(function(index)
    38.                 {
    39.                     var theta = alpha * index;
    40.                     var pointx  =  Math.floor(Math.cos( theta ) * radius);
    41.                     var pointy  = Math.floor(Math.sin( theta ) * radius );
    42.                     // Выводим координаты X и Y
    43.                     $(this).css('margin-left', pointx + x + 'px');
    44.                     $(this).css('margin-top', pointy  + y  + 'px');
    45.                 });
    46.                }
    47.  
    48.  
    49.  
    50.  
    51.  
    52.             $('.circle').find('.CiText > div').css({
    53.                 top:$('.circle').height()/2-$('.circle').find('.CiText > div').height()/2,
    54.                 left:$('.circle').width()/2-$('.circle').find('.CiText > div').width()/2
    55.             })
    56.             var position = $('.circle').position();
    57.             position.top=29;
    58.             position.left=29;
    59.  
    60.  
    61.             drawCircle('.CiFrend > div', 0, 68, 90, 77, 76);
    62.  
    63.             $('.circle').hoverIntent(function(){
    64.                 $(this).addClass('CiOpen')
    65.                 .css({'top':position.top, 'left':position.left});
    66.                 $(this).animate({
    67.                     'height':182,
    68.                     'width':182,
    69.                     'top':0,
    70.                     'left':0
    71.                 },100,function(){
    72.                     //$(this).removeClass('CiClose');
    73.                     $(this).find('.CiFrend > div').fadeIn(200)
    74.                 })
    75.                 .find('.CiText > div').animate({
    76.                     'top':182/2-$(this).find('.CiText > div').height()/2,
    77.                     'left':182/2-$(this).find('.CiText > div').width()/2+1
    78.                 },100)
    79.              }
    80.              ,function(){
    81.                
    82.                 //$(this).addClass('CiClose');
    83.                 $(this).find('.CiFrend > div').hide();
    84.                 $(this).animate({
    85.                     'height':125,
    86.                     'width':125,
    87.                     'left':position.left,
    88.                     'top':position.top
    89.                 },100,function(){
    90.                     $(this)
    91.                     .css({'top':0, 'left':0})
    92.                     .removeClass('CiOpen')
    93.                     $(this).find('.CiFrend > div').hide();
    94.                 })
    95.                 $(this).find('.CiText > div').animate({
    96.                     'top':125/2-$(this).find('.CiText > div').height()/2,
    97.                     'left':125/2-$(this).find('.CiText > div').width()/2
    98.                 },100)
    99.             }
    100.             )
    101.  
    102.         })
    103.     </script>
    104.     <style type="text/css">
    105.         .row_circle{
    106.             display: inline-block;
    107.             position: relative;
    108.             width: 150px;
    109.             height: 183px;
    110.             padding: 1px;
    111.             position: relative;
    112.             vertical-align: top;
    113.         }
    114.         .circle{
    115.            
    116.             overflow: hidden;
    117.         }
    118.         .CiClose{
    119.             background-repeat: no-repeat;
    120.             border-radius: 63px 63px 63px 63px;
    121.             height: 125px;
    122.             margin: 31px;
    123.             position: relative;
    124.             vertical-align: top;
    125.             width: 125px;
    126.             z-index: 5;
    127.             background-image: url("//ssl.gstatic.com/s2/oz/images/sge/personal_circle_closed.png");
    128.         }
    129.         .CiOpen{
    130.             background-repeat: no-repeat;
    131.             border-radius: 92px 92px 92px 92px;
    132.     /*      height: 183px;
    133.             width: 183px;*/
    134.             margin: 2px;
    135.             position: relative;
    136.             vertical-align: top;
    137.             z-index: 2;
    138.             background: url("//ssl.gstatic.com/s2/oz/images/sge/personal_circle_open.png") no-repeat scroll center center transparent;
    139.         }
    140.         .circle .CiText > div{
    141.             color: #FFFFFF;
    142.             cursor: pointer;
    143.             font-size: 13px;
    144.             position: relative;
    145.             text-align: center;
    146.             width: 88px;
    147.             text-shadow:none;
    148.         }
    149.         .circle .CiText > div span{
    150.             display: block;
    151.         }
    152.         .circle .CiText > div div{
    153.             font-size: 16px;
    154.             font-weight: bold;
    155.             margin-top: 4px;
    156.             opacity: 0.5;
    157.         }
    158.         .CiFrend > div{
    159.             background-position: center center;
    160.             background-repeat: no-repeat;
    161.             background-size: 30px auto;
    162.             border-radius: 15px 15px 15px 15px;
    163.             cursor: url("//ssl.gstatic.com/s2/oz/images/sge/openhand_8_8.cur"), move;
    164.             height: 30px;
    165.             left: 0;
    166.             overflow: hidden;
    167.             position: absolute;
    168.             top: 0;
    169.             width: 30px;
    170.             display:none;
    171.         }
    172.     </style>
    173.  
    174. </head>
    175.     <div class="block_circle">
    176.         <div class="row_circle">
    177.             <div class="circle CiClose">
    178.                 <div class="CiText">
    179.                     <div>
    180.                         <span class="name_circle">Друзья</span>
    181.                         <div class="count_frend">0</div>
    182.                     </div>
    183.                 </div>
    184.                 <div class="CiFrend">
    185.                     <div style="background-image: url('//lh6.googleusercontent.com/-918KWvf6KsU/AAAAAAAAAAI/AAAAAAAAAHE/rew9eGIt00g/photo.jpg?sz=48');">
    186.                         <img style="display:none"/>
    187.                     </div>
    188.                     <div style="background-image: url('//lh6.googleusercontent.com/-918KWvf6KsU/AAAAAAAAAAI/AAAAAAAAAHE/rew9eGIt00g/photo.jpg?sz=48');">
    189.                         <img style="display:none"/>
    190.                     </div>
    191.                     <div style="background-image: url('//lh6.googleusercontent.com/-918KWvf6KsU/AAAAAAAAAAI/AAAAAAAAAHE/rew9eGIt00g/photo.jpg?sz=48');">
    192.                         <img style="display:none"/>
    193.                     </div>
    194.                     <div style="background-image: url('//lh6.googleusercontent.com/-918KWvf6KsU/AAAAAAAAAAI/AAAAAAAAAHE/rew9eGIt00g/photo.jpg?sz=48');">
    195.                         <img style="display:none"/>
    196.                     </div>
    197.                     <div style="background-image: url('//lh6.googleusercontent.com/-918KWvf6KsU/AAAAAAAAAAI/AAAAAAAAAHE/rew9eGIt00g/photo.jpg?sz=48');">
    198.                         <img style="display:none"/>
    199.                     </div>
    200.                 </div>
    201.             </div>
    202.         </div>
    203.     </div>
    204.     <div class="block_circle">
    205.         <div class="row_circle">
    206.             <div class="circle CiClose">
    207.                 <div class="CiText">
    208.                     <div>
    209.                         <span class="name_circle">Друзья</span>
    210.                         <div class="count_frend">0</div>
    211.                     </div>
    212.                 </div>
    213.                 <div class="CiFrend">
    214.                     <div style="background-image: url('//lh6.googleusercontent.com/-918KWvf6KsU/AAAAAAAAAAI/AAAAAAAAAHE/rew9eGIt00g/photo.jpg?sz=48');">
    215.                         <img style="display:none"/>
    216.                     </div>
    217.                     <div style="background-image: url('//lh6.googleusercontent.com/-918KWvf6KsU/AAAAAAAAAAI/AAAAAAAAAHE/rew9eGIt00g/photo.jpg?sz=48');">
    218.                         <img style="display:none"/>
    219.                     </div>
    220.                     <div style="background-image: url('//lh6.googleusercontent.com/-918KWvf6KsU/AAAAAAAAAAI/AAAAAAAAAHE/rew9eGIt00g/photo.jpg?sz=48');">
    221.                         <img style="display:none"/>
    222.                     </div>
    223.                     <div style="background-image: url('//lh6.googleusercontent.com/-918KWvf6KsU/AAAAAAAAAAI/AAAAAAAAAHE/rew9eGIt00g/photo.jpg?sz=48');">
    224.                         <img style="display:none"/>
    225.                     </div>
    226.                     <div style="background-image: url('//lh6.googleusercontent.com/-918KWvf6KsU/AAAAAAAAAAI/AAAAAAAAAHE/rew9eGIt00g/photo.jpg?sz=48');">
    227.                         <img style="display:none"/>
    228.                     </div>
    229.                 </div>
    230.             </div>
    231.         </div>
    232.     </div>
    233. </body>
    234. </html>
    235.  
    [js][/js][js][/js]