jQuery超酷打字机效果js代码

版权:原创 更新时间:1年以上
[该文章底部包含文件资源,可根据自己情况,决定是否下载资源使用,时间>金钱,如有需要,立即查看资源]

以下是 jQuery超酷打字机效果js代码 的示例演示效果:

当前平台(PC电脑)
  • 平台:

部分效果截图:

jQuery超酷打字机效果js代码

HTML代码(index.html):

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jQuery超酷打字机效果</title>
    <style type="text/css" media="screen, projection">
        #ticker {
            height: 12em;
            padding: 0.6em 0;
            margin: 0 0 1.8em 0;
            border-top: 3px solid #efefef;
            border-bottom: 3px solid #efefef;
            position: relative;
        }

        #ticker .cursor {
            display: inline-block;
            background: #565c61;
            width: 0.6em;
            height: 1em;
            text-align: center;
        }

        #ticker p {
            margin-bottom: 0.8em;
        }

        #ticker code {
            margin: 0.4em 0.4em;
            display: block;
        }

        #ticker .next {
            position: absolute;
            bottom: 1em;
        }
    </style>
    <script type="text/javascript" SRC="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" SRC="js/jquery.jticker.js"></script>
    <script type="text/javascript">
<!--
  jQuery(document).ready(function(){
    // Instantiate jTicker
	jQuery("#ticker").ticker({
 		cursorList:  " ",
 		rate:        10,
 		delay:       4000
	}).trigger("play").trigger("stop");

    // Trigger events
    jQuery(".stop").click(function(){
        jQuery("#ticker").trigger("stop");
        return false;
    });

    jQuery(".play").click(function(){
        jQuery("#ticker").trigger("play");
        return false;
    });

    jQuery(".speedup").click(function(){
        jQuery("#ticker")
        .trigger({
            type: "control",
            item: 0,
            rate: 10,
            delay: 4000
        })
        return false;
    });

    jQuery(".slowdown").click(function(){
        jQuery("#ticker")
        .trigger({
            type: "control",
            item: 0,
            rate: 90,
            delay: 8000
        })
        return false;
    });

    jQuery(".next").live("click", function(){
        jQuery("#ticker")
        .trigger({type: "play"})
        .trigger({type: "stop"});
        return false;
    });

    jQuery(".style").click(function(){
        jQuery("#ticker")
        .trigger({
            type: "control",
            cursor: jQuery("#ticker").data("ticker").cursor.css({width: "4em", background: "#efefef", position: "relative", top: "1em", left: "-1em"})
        })
        return false;
    });
  });
    </script>
</head>
<body>
    <div id="content">
        <h2>jTicker Demo  </h2>
        <div id="ticker">
            <div>
                <h3>What does jTicker do?</h3>
                <p>jTicker takes an elements' children and displays them one by one, in sequence, writing their text 'ticker tape' style. It is smart enough to ticker text from an element heirarchy, inserting elements back into the DOM tree as it needs them. That means almost any content can be 'tickered'.</p>
                <p>It can be controlled with jQuery events.</p>
                <a class="next" href="#">next</a>
            </div>
            <div>
                <h3>Not my cup of tea, really, ...</h3>
                <p>annoying little blinky things trying to distract attention when you want to get on with the serious business of reading a website, but if it's your thing, here it is.</p>
                <a class="next" href="#">next</a>
            </div>
            <div>
                <h3>jTicker has some neat features:</h3>
                <ul>
                    <li>jTicker can be declared on any element, and it respects that element's DOM tree, printing it back out with the same hierarchy.</li>
                    <li>jTicker handles any number of alternating cursors (or just one).</li>
                    <li>jTicker's cursor container is styleable using the class .cursor, or can be defined as your own jQuery object</li>
                    <li>jTicker reacts to jQuery events "play", "stop" and "control". You can try them out below.</li>
                </ul>
                <a class="next" href="#">next</a>
            </div>

            <div>
                <h3>There is one caveat:</h3>
                <ul>
                    <li>
                        <span>jTicker can't understand text and children at the same level (I don't know how to do that yet), so if you want some text and then a link, you have to wrap the text in, say, a span, like this:</span>
                        <code>|span| some text |/span| |a|and then a link|/a|</code>
                    </li>
                    <li>But obviously not with those brackets. That's another thing, jTicker is not good at handling html character entities. So make that two caveats.</li>
                </ul>
                <a class="next" href="#">next</a>
            </div>
        </div>
    </div>
</body>
</html>

JS代码(jquery.jticker.js):

// jquery.ticker.js// 0.9.1 - beta// Stephen Band//// Project and documentation site:// http://webdev.stephband.info/jticker///// Dependencies:// jQuery 1.2.3 - (www.jquery.com)//// Instantiate and play with:// jQuery(element).ticker({
	options}
).trigger("play");
	(function(jQuery){
	// VARvar name = "ticker";
	// Name of the plugin// FUNCTIONSfunction indexify(i,length){
	return (i >= length) ? indexify(i-length,length):((i < 0) ? indexify(i+length,length):i);
}
function advanceItem(elem){
	var data = elem.data(name);
	var length;
	for (var i=0;
	i<200;
	i++){
	if (!data.content[i]){
	length = i;
	break;
}
}
data.nextItem = indexify((data.nextItem || 0),length);
	data.currentItem = data.nextItem;
	data.elemIndex = [data.currentItem];
	data.charIndex = 0;
	data.nextItem++;
}
function makeFamily(elem){
	var obj ={
	elem:elem.clone().empty()}
;
	var children = elem.children();
	if (children.length){
	children.each(function(i){
	obj[i] = makeFamily(jQuery(this));
}
);
	return obj;
}
else{
	obj.text = elem.text() return obj;
}
}
function checkFamily(content,index){
	var newIndex;
	if (content[index[0]]){
	if (content[index[0]].text){
	return content[index[0]];
}
else if (index.length == 1){
	return true;
}
else{
	newIndex = jQuery.makeArray(index);
	return checkFamily(content[newIndex[0]],newIndex.splice(1,newIndex.length));
}
}
else{
	return false;
}
}
function incrementIndex(index){
	if (index.length > 1){
	index[index.length-1]++;
	return index;
}
else{
	return false;
}
}
function buildIndex(content,index){
	if (index === false){
	return false;
}
var obj = checkFamily(content,index);
	if (obj === false){
	return buildIndex(content,incrementIndex(index.slice(0,index.length-1)));
}
else if (obj === true){
	index[index.length] = 0;
	return buildIndex(content,index);
}
else{
	return index;
}
}
function buildFamily(elem,content,index,data){
	var newIndex,newElem;
	var child = elem.children().eq(index[0]);
	if (!index.length){
	return{
	readout:elem,text:content.text}
;
}
else if (child.length){
	newElem = child;
}
else{
	newElem = content[index[0]].elem.appendTo(elem);
}
newIndex = jQuery.makeArray(index).slice(1,index.length);
	return buildFamily(newElem,content[index[0]],newIndex,data);
}
function initElem(elem){
	var data = elem.data(name);
	jQuery("*",elem).empty();
	elem.empty();
	data.start = 0;
	data.sum = 0;
	if (data.cursorIndex){
	cursorIndex = 0;
}
}
function initChild(elem){
	var data = elem.data(name);
	data.start = data.sum;
}
function ticker(elem,threadIndex,data){
	var index,letter;
	// Switch cursor if (data.cursorIndex !== false){
	data.cursorIndex = indexify(data.cursorIndex+1,data.cursorList.length);
	data.cursor.html(data.cursorList[data.cursorIndex]);
}
else{
	data.cursor.html(data.cursorList);
}
// Add character to readout index = data.charIndex - data.start;
	letter = data.text.charAt(index-1);
	data.cursor.before(letter);
	if (data.charIndex >= data.sum){
	data.cursor.remove();
	data.elemIndex = incrementIndex(data.elemIndex);
	return tape(elem,threadIndex);
}
else{
	return setTimeout(function(){
	if (data.eventIndex == threadIndex){
	data.charIndex++;
	ticker(elem,threadIndex,data);
}
threadIndex = null;
}
,data.rate);
}
}
function tape(elem,threadIndex){
	var data = elem.data(name);
	if (data.eventIndex == threadIndex){
	data.elemIndex = buildIndex(data.content,data.elemIndex);
	//console.log('INDEX '+data.elemIndex);
	if (data.elemIndex === false){
	return setTimeout(function(){
	if (data.running && (data.eventIndex == threadIndex)){
	advanceItem(elem);
	return tape(elem,threadIndex);
}
threadIndex = null;
}
,data.delay);
}
else if (!data.charIndex){
	initElem(elem);
}
else{
	initChild(elem);
}
jQuery.extend(data,buildFamily(elem,data.content,data.elemIndex));
	data.sum = data.sum + data.text.length;
	data.readout.append(data.cursor);
	return ticker(elem,threadIndex,data);
}
}
// PLUGIN DEFINITIONjQuery.fn[name] = function(options){
	// Add or overwrite options onto defaults var o = jQuery.extend({
}
,jQuery.fn.ticker.defaults,options);
	// Iterate matched elements return this.each(function(){
	var elem = jQuery(this);
	elem .data(name,{
	rate:o.rate,delay:o.delay,content:makeFamily(elem),cursor:o.cursor,cursorList:o.cursorList,cursorIndex:(typeof(o.cursorList) == "object") ? 0:false,nextItem:0,eventIndex:0}
) .bind("stop",function(e){
	var data = elem.data(name);
	data.running = false;
}
) .bind("play",function(e){
	var data = elem.data(name);
	data.eventIndex++;
	data.running = true;
	data.nextItem = (e.item || data.nextItem);
	advanceItem(elem);
	tape(elem,data.eventIndex);
}
) .bind("control",function(e){
	var data = elem.data(name);
	jQuery().extend(data,{
	nextItem:e.item,rate:e.rate,delay:e.delay}
);
}
) .children() .remove();
}
);
}
;
	// PLUGIN DEFAULTSjQuery.fn[name].defaults ={
	rate:40,// Speed to print message. delay:2000,// Pause to read message. cursorList:"_",// A string or an array of strings or jQuery objects. If an array,the cursor loops through the array. cursor:jQuery('<span class="cursor" />')}
}
)(jQuery);
	
附件:下载该文件资源,减少时间成本(增值服务)
留言
该资源可下载
File Source
.rar
22.77 KB
jquery特效7
最新结算
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
HTML5实现CSS滤镜图片切换特效代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery+css3实现信封效果
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
我们力求给您提供有用的文章,再此基础上,会附加营收资源,不做任何广告,让平台可以更好发展 若您发现您的权利被侵害,或使用了您的版权,请发邮件联系 sunlifel@foxmail.com ggbig觉得 : 不提供源码的文章不是好文章
合作伙伴
联系我们
  • QQ:21499807
  • 邮箱:sunlifel@foxmail.com
  • QQ扫一扫加QQ
    QQ扫一扫
Copyright 2023-2024 ggbig.com·皖ICP备2023004211号-1
打赏文章