te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - delay link click on all page links - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - delay link click on all page links - Stack Overflow

programmeradmin2浏览0评论

I'm looking for a way to have every link on a page delay by a second, so that a fade-out animation can occur Essentially, you click on an area over an image and the image fades out, but if there's no delay, the animation isn't seen. I have 4 areas on this image. Two go to page A and two go to page b. Any thoughts?

I'm looking for a way to have every link on a page delay by a second, so that a fade-out animation can occur Essentially, you click on an area over an image and the image fades out, but if there's no delay, the animation isn't seen. I have 4 areas on this image. Two go to page A and two go to page b. Any thoughts?

Share Improve this question edited Feb 5, 2011 at 6:14 T.J. Crowder 1.1m199 gold badges2k silver badges1.9k bronze badges asked Feb 4, 2011 at 22:31 salemsalem 231 silver badge3 bronze badges 8
  • 4 Sounds like a great way to irritate users. – T.J. Crowder Commented Feb 4, 2011 at 22:35
  • 1 It's worked well so far. The click delay only needs to be half a second. It's an artistic sort of site. – salem Commented Feb 4, 2011 at 22:37
  • Are you using any JavaScript libraries, or just raw stuff? (And I'd be interested in how you know it's worked well so far. I certainly wouldn't bother to tell you why I was leaving the site and not ing back. Moreover, surely you're not currently doing this, so you don't really know? Since you're asking how to do it...) – T.J. Crowder Commented Feb 4, 2011 at 22:37
  • Don't do that. Nothing else to say. – ThiefMaster Commented Feb 4, 2011 at 22:38
  • It sounds OK to me, but a better way of doing this would be AJAX webpages – JCOC611 Commented Feb 4, 2011 at 22:48
 |  Show 3 more ments

3 Answers 3

Reset to default 7

You could capture (and halt) the link click event and set a timeout to redirect to the link's href attrib after 1000ms.

Using jQuery:

$("#a_context a").click(function(e) {
  e.preventDefault();
  var destination = $(this).attr('href');
  setTimeout(function() { window.location.href = destination; }, 1000);
});

Not sure if that's the best way, but is all I can think of.

You can do it with jQuery:

$('a').click(function(e) {
    var anchor = $(this), h;
    h = anchor.attr('href');
    e.preventDefault();
    anchor.animate({'opacity' : 0}, 1000, function() {
        window.location = h;
    });
});
var aTags = document.getElementsByTagName('a');

for (var i = 0; i < aTags.length; i++) {
    if (document.addEventListener) {
        aTags[i].addEventListener('click', function(e) {
            e.preventDefault();

            // fade out here then
            // setTimeout(function(){ 
            //   window.location.href = e.currentTarget.href;
            // }, 1000);
        }, false);
    } else {
        aTags[i].attachEvent('onclick', function(e) {
            e.returnValue = false;

            // fade out here then on plete
            // setTimeout(function(){ 
            //   window.location.href = e.srcElement.href;
            // }, 1000);
        });
    }
}
发布评论

评论列表(0)

  1. 暂无评论