Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.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 将内联硬编码jQuery函数传输到变量_Javascript_Jquery_Html_Css_Variables - Fatal编程技术网

Javascript 将内联硬编码jQuery函数传输到变量

Javascript 将内联硬编码jQuery函数传输到变量,javascript,jquery,html,css,variables,Javascript,Jquery,Html,Css,Variables,我有以下代码: <!-- work item 1 --> <li id="portfolio-1" class="col-12 col-sm-6 col-md-6 col-lg-4"> <figure class="box box--sm text-center"> <h4 class="brand--font-standard">Project Title</h4&g

我有以下代码:

      <!-- work item 1 -->
      <li id="portfolio-1" class="col-12  col-sm-6  col-md-6  col-lg-4">
        <figure class="box  box--sm  text-center">
            <h4 class="brand--font-standard">Project Title</h4>
              <div class="row">
              <div class="col-xs-offset-2  col-xs-8  col-sm-offset-1  col-sm-10  col-md-offset-2  col-md-8  col-lg-offset-3  col-lg-6">
                  <img src="img/globe.jpg" class="img-responsive" alt="globe">
                </div>
              </div>
            <figcaption>
              <p>Project comment</p>
              <a href="#" class="pull-right  brand--font" onclick="$('.work--detail').addClass('work--detail_show'); $('#work-2, #work-3, #work-4, #work-5, #work-6').hide(); $('#work-1').slideDown(); $('html, body').animate({scrollTop: $('.hidden-content-top').offset().top - 110 }, 1000); return false;">View</a>
            </figcaption>
        </figure>
      </li><!-- /work item 1 -->
感谢您的帮助

PS-我可以处理第二部分(根据窗口宽度等添加偏移值)


PPS-我是js的新手,所以请温柔一点:)

如果我是你,我会给代码添加一点清晰:

var _getInnerWidth = function () {

    if(typeof window.innerWidth !== 'undefined'){
      innerWidth = window.innerWidth;
    } else {
      innerWidth = document.documentElement.clientWidth;
    }

    return innerWidth;
}
您的代码应该按原样工作。我试了一下,然后回到1704年

我在这里附上一个plunker,其中有一个例子,是我根据你所做的描述构建的。希望能有帮助


你也会感兴趣的读这个帖子:也可以考虑把你的函数作为函数声明:<代码>函数yGETnNeLead(){//} 这样,你可以确信你可以在定义函数之前调用函数,如果你尝试调用函数,它是一个函数表达式:<代码> var vgutnEngule=函数(){/}在定义它之前调用它是行不通的。也请阅读这篇文章:函数声明vs函数表达式:嗨@Guillermo,感谢你的帮助。但这更是我关心的问题的第一部分。在你的函数中
$(this).attr('id'))
将返回单击的li id,然后您应该对id应用一些转换-替换将正常工作-使用原始id应用.hide,使用新id apply.show,让我知道它是否适合您。请在您的函数中尝试以下操作:
var receivedId=$(this.attr('id'),newId=receivedId.replace('portfolio','work'))
这里有新的和“旧”的id,请记住,如果要在选择器中使用它们,应附加“#”以使其正常工作。
var _getInnerWidth = function () {
return typeof window.innerWidth !== 'undefined' ? window.innerWidth : document.documentElement.clientWidth;
var _getInnerWidth = function () {

    if(typeof window.innerWidth !== 'undefined'){
      innerWidth = window.innerWidth;
    } else {
      innerWidth = document.documentElement.clientWidth;
    }

    return innerWidth;
}