javascript - CodePen javascript 代码在本地不起作用

标签 javascript jquery codepen

首先我是 javascript 的新手 我想重用这个codepen中的代码

    $('a[href*=#]').click(function(){
  return false;
});


var animationEndEvent = "webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend";

var Person = {
  wrap: $('#people'),
  people: [
    {
      name: 'Linda',
      age: 25,
      img: "https://i.imgur.com/QZuGC10.jpg"
    },
    {
      name: 'Lisa',
      age: 20,
      img: "https://i.imgur.com/1EWwp59.jpg"
    },
    {
      name: 'Sandra',
      age: 18,
      img: "https://i.imgur.com/Lu3laIj.jpg"
    },
    {
      name: 'Chloe',
      age: 18,
      img: "https://i.imgur.com/WgYIxhw.png"
    },
    {
      name: 'Alexa',
      age: 23,
      img: "https://i.imgur.com/D0PQegY.png"
    },
    {
      name: 'Maria',
      age: 21,
      img: "https://i.imgur.com/eqd5IhH.jpg"
    },
    {
      name: 'Emma',
      age: 24,
      img: "https://i.imgur.com/4F9NXPo.png"
    },
    {
      name: 'Sara',
      age: 18,
      img: "http://i40.tinypic.com/ofxe21.jpg"
    },
    {
      name: 'Lara',
      age: 22,
      img: "https://i.imgur.com/HMkdN6A.jpg"
    }
  ],   
  add: function(){
    var random =     this.people[Math.floor(Math.random() * this.people.length)];
    this.wrap.append("<div class='person'><img alt='" + random.name + "' src='" + random.img + "' /><span><strong>" + random.name + "</strong>, " + random.age + "</span></div>");
  }
}

var App = {
  yesButton: $('.button.yes .trigger'),
  noButton: $('.button.no .trigger'),
  blocked: false,
  like: function(liked){
    var animate = liked ? 'animateYes' : 'animateNo';
    var self = this;
    Person.add();
    if (!this.blocked) {
      this.blocked = true;           
      $('.person').eq(0).addClass(animate).one(animationEndEvent, function() {
        $(this).remove();
        self.blocked = false;
      });
    }
  }
};

var Phone = {
  wrap: $('#phone'),
  clock: $('.clock'),
  updateClock: function() {
    var date = new Date();
    var hours = date.getHours();
    var min = date.getMinutes();
    hours = (hours < 10 ? "0" : "") + hours;
    min = (min < 10 ? "0" : "") + min;
    var str = hours + ":" + min;
    this.clock.text(str);
  }
}

App.yesButton.on('mousedown', function() {
  App.like(true);
});

App.noButton.on('mousedown', function() {
  App.like(false);
});

$(document).ready(function() {
  Person.people.forEach(function(person){
    new Image().src = person.img; 
  });
  Phone.updateClock();
  setInterval('Phone.updateClock()', 1000);

  Person.add();
  Person.add();
  Person.add();
  Person.add();
});

(https://codepen.io/renatorib/pen/extCA)。 但是我不能让它在本地工作。 我已经插入了 jquery(他使用的版本相同//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js) 我已经将 sass 转换为 css。

它看起来一样,但它的 javascript 部分不起作用(没有照片,没有按钮,什么都没有..)没有控制台错误... 我不知道还能做什么..

PD:对不起我的英语,我希望我能解释清楚

最佳答案

替换它并使用它 jQuery版本在底部。

 $('a[href*="#!..."]').click(function(){
  return false;
});

Full Repo

关于javascript - CodePen javascript 代码在本地不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57364209/

相关文章:

javascript - 在 Swift 中循环遍历 JavaScript 元素,WKWebView

javascript - jQuery 如何从 responseText 中读取这个 JSON 字符串

Javascript onClick 在 Safari 或 Chrome 中不起作用

javascript - Javascript HTML播放声音仅一次,但是发生了更多奇怪的事情

html - 列卡在左边,没有散开

javascript - Ember 更复杂的例子

javascript - $.ajax 调用有效,$http.get() 无效(404,未找到)

javascript - jquery AJAX 加载未显示

javascript - js : variable gets overwritten on click

javascript - 为什么我会收到此错误消息? "Uncaught Initmap is not a function"