Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要帮助调整脚本以使其仅在满足屏幕大小时工作吗_Javascript_Media Queries_Typed.js - Fatal编程技术网

Javascript 需要帮助调整脚本以使其仅在满足屏幕大小时工作吗

Javascript 需要帮助调整脚本以使其仅在满足屏幕大小时工作吗,javascript,media-queries,typed.js,Javascript,Media Queries,Typed.js,我使用的是typed.js,我不希望它在手机上工作。这是我的密码: jQuery( document ).ready( function ( $ ) { // Typed Span Element $( window ).on( 'resize', function ( ) { var win = $( this ); if ( win.width( ) < 765 ) { $( ".typed-element" ).

我使用的是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
            } );
        }
    } );

} );
jQuery(文档).ready(函数($){
//类型跨度单元
$(窗口).on('resize',函数(){
var win=$(此);
if(win.width()<765){
$(“.typed元素”).typed({
字符串:[“Aim^1500”],
打字速度:200,
循环:false,
是的,
cursorChar:“|”,
//开始打字前的时间
开始时间:0,
//退格速度
后退速度:0,
//退格前的时间
反向延迟:500
} );
}否则{
$(“.typed元素”).typed({
字符串:[“目标^1500”、“游戏^1500”、“互联网^1500”],
打字速度:200,
循环:对,
是的,
cursorChar:“|”,
//开始打字前的时间
开始时间:0,
//退格速度
后退速度:0,
//退格前的时间
反向延迟: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
            } );
        }
    } );

} );
jQuery(文档).ready(函数($){
//这是一个手机,没有理由激活类型化元素。
//return停止对其余代码的处理。
if($(窗口).width()<765)返回
//这不应该在手机上被点击,在其他任何地方都可以。
//类型跨度单元
$(窗口).on('resize',函数(){
var win=$(此);
if(win.width()<765){
$(“.typed元素”).typed({
字符串:[“Aim^1500”],
打字速度:200,
循环:false,
是的,
cursorChar:“|”,
//开始打字前的时间
开始时间:0,
//退格速度
后退速度:0,
//退格前的时间
反向延迟:500
} );
}否则{
$(“.typed元素”).typed({
字符串:[“目标^1500”、“游戏^1500”、“互联网^1500”],
打字速度:200,
循环:对,
是的,
cursorChar:“|”,
//开始打字前的时间
开始时间:0,
//退格速度
后退速度:0,
//退格前的时间
反向延迟: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
            } );
        }
    } );

} );
jQuery(文档).ready(函数($){
//这是一个手机,没有理由激活类型化元素。
//return停止对其余代码的处理。
if($(窗口).width()<765)返回
//这不应该在手机上被点击,在其他任何地方都可以。
//类型跨度单元
$(窗口).on('resize',函数(){
var win=$(此);
if(win.width()<765){
$(“.typed元素”).typed({
字符串:[“Aim^1500”],
打字速度:200,
循环:false,
是的,
cursorChar:“|”,
//开始打字前的时间
开始时间:0,
//退格速度
后退速度:0,
//退格前的时间
反向延迟:500
} );
}否则{
$(“.typed元素”).typed({
字符串:[“目标^1500”、“游戏^1500”、“互联网^1500”],
打字速度:200,
循环:对,
是的,
cursorChar:“|”,
//开始打字前的时间
开始时间:0,
//退格速度
后退速度:0,
//退格前的时间
反向延迟:500
} );
}
} );
} );

这些是浏览器高度和宽度的变量

window.screen.availHeight
window.screen.availWidth
如果window.screen.availWidth小于765,则为移动设备

if(window.screen.availWidth < 765){
    //your code here
}
if(window.screen.availWidth<765){
//你的代码在这里
}

这些是浏览器高度和宽度的变量

window.screen.availHeight
window.screen.availWidth
如果window.screen.availWidth小于765,则为移动设备

if(window.screen.availWidth < 765){
    //your code here
}
if(window.screen.availWidth<765){
//你的代码在这里
}