响应式设计 - 修改JQuery以改变手机和平板电脑的操作

时间:2013-02-01 12:29:34

标签: jquery responsive-design

我有以下代码,鼠标悬停在图像上方并显示div下面的内容,单击div后会转到另一页。鼠标Overs不适用于平板电脑等,所以我没有将鼠标悬停在单击鼠标上以显示div内容。但是,当我将鼠标悬停更改为单击时,div会显示,然后在一个操作中进入下一页。我需要两次点击。任何人都可以建议我如何实现这个目标吗?

非常感谢提前。

$(document).ready(function() {

    //Custom settings
    var style_in = 'easeOutBounce';
    var style_out = 'jswing';
    var speed_in = 1000;
    var speed_out = 250;

    //Calculation for corners
    var neg = Math.round($('.qitem').width() / 2) * (-1);  
    var pos = neg * (-1);  
    var out = pos * 2;
    var pos_h = Math.round($('.qitem').height() / 2);   

    $('.qitem').each(function () {

        //grab the anchor and image path
        url = $(this).find('a').attr('href');
        img = $(this).find('img').attr('src');

        //remove the image
        $('img', this).remove();

        //append four corners/divs into it
        $(this).append('<div class="topLeft"></div><div class="topRight"></div><div class="bottomLeft"></div><div class="bottomRight"></div>');

        //set the background image to all the corners
        $(this).children('div').css('background-image','url('+ img + ')');

        //set the position of corners
        $(this).find('div.topLeft').css({top:0, left:0, width:pos, height:pos_h});  
        $(this).find('div.topRight').css({top:0, left:pos, width:pos, height:pos_h});   
        $(this).find('div.bottomLeft').css({bottom:0, left:0, width:pos, height:pos_h});
        $(this).find('div.bottomRight').css({bottom:0, left:pos, width:pos, height:pos_h}); 

    }).hover(function () {  //change to click

        //animate the position
        $(this).find('div.topLeft').stop(false, true).animate({top:neg, left:neg}, {duration:speed_out, easing:style_out});
        $(this).find('div.topRight').stop(false, true).animate({top:neg, left:out}, {duration:speed_out, easing:style_out});   
        $(this).find('div.bottomLeft').stop(false, true).animate({bottom:neg, left:neg}, {duration:speed_out, easing:style_out});  
        $(this).find('div.bottomRight').stop(false, true).animate({bottom:neg, left:out}, {duration:speed_out, easing:style_out}); 

    },

    function () {

        //put corners back to the original position
        $(this).find('div.topLeft').stop(false, true).animate({top:0, left:0}, {duration:speed_in, easing:style_in});  
        $(this).find('div.topRight').stop(false, true).animate({top:0, left:pos}, {duration:speed_in, easing:style_in});   
        $(this).find('div.bottomLeft').stop(false, true).animate({bottom:0, left:0}, {duration:speed_in, easing:style_in});
        $(this).find('div.bottomRight').stop(false, true).animate({bottom:0, left:pos}, {duration:speed_in, easing:style_in}); 

    }).click (function () {

        //go to the url
        window.location = $(this).find('a').attr('href');  
    });

});

1 个答案:

答案 0 :(得分:0)

如果您通过点击替换$.hover(),则必须将最后$.click替换为$.dblclick,否则将同时触发两个点击处理程序。