gpt4 book ai didi

javascript - 需要帮助调整脚本,使其仅在满足屏幕尺寸时才起作用

转载 作者:行者123 更新时间:2023-11-28 05:53:30 27 4
gpt4 key购买 nike

我正在使用 typed.js,但我不希望它在移动设备上运行。这是我的代码:

jQuery( document ).ready( function ( $ ) {
// Typed Span Element
$( window ).on( 'resize', function ( ) {
var win = $( this );
if ( win.width( ) < 765 ) {
$( ".typed-element" ).typed( {
strings: [ "Aim^1500" ],
typeSpeed: 200,
loop: false,
showCursor: true,
cursorChar: "|",
// time before typing starts
startDelay: 0,
// backspacing speed
backSpeed: 0,
// time before backspacing
backDelay: 500
} );
} else {
$( ".typed-element" ).typed( {
strings: [ "Aim^1500", "Game^1500", "Internet^1500" ],
typeSpeed: 200,
loop: true,
showCursor: true,
cursorChar: "|",
// time before typing starts
startDelay: 0,
// backspacing speed
backSpeed: 0,
// time before backspacing
backDelay: 500
} );
}
} );

} );

如果有办法完全停止脚本那就更理想了。我现在的解决方法是调整字符串以仅显示一个单词,也就是说,如果这段代码有效的话。

最佳答案

如果您在移动设备上加载此内容,那么您在启动 JavaScript 之前就知道 window.width()。

jQuery( document ).ready( function ( $ ) {
// This is a mobile and there is no reason to activate the typed element.
// return stops the processing of the rest of the code.
if($(window).width() < 765 ) return

//This should NEVER be hit on a mobile and will be just fine on everything else.
// Typed Span Element
$( window ).on( 'resize', function ( ) {
var win = $( this );
if ( win.width( ) < 765 ) {
$( ".typed-element" ).typed( {
strings: [ "Aim^1500" ],
typeSpeed: 200,
loop: false,
showCursor: true,
cursorChar: "|",
// time before typing starts
startDelay: 0,
// backspacing speed
backSpeed: 0,
// time before backspacing
backDelay: 500
} );
} else {
$( ".typed-element" ).typed( {
strings: [ "Aim^1500", "Game^1500", "Internet^1500" ],
typeSpeed: 200,
loop: true,
showCursor: true,
cursorChar: "|",
// time before typing starts
startDelay: 0,
// backspacing speed
backSpeed: 0,
// time before backspacing
backDelay: 500
} );
}
} );

} );

关于javascript - 需要帮助调整脚本,使其仅在满足屏幕尺寸时才起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37893716/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com