https://gitee.com/ishouke/front_end_plugin/blob/master/jquery-3.2.1.min.js
因为js是单线程的,所以有js写贪吃蛇可以少考虑很多东西,感觉非常方便。今天给大家介绍一个非常简单的贪吃蛇写法。我说的非常简单勒,就是指没有游戏结束,也不会变长。哈哈,反正就是非常简单了。
携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第11天,点击查看活动详情 >>
效果: 需求: 1.记录循环滚动; 2.每组记录之间不能有留白; 3.每条记录上移到容器的顶部时要停顿一下; 4.鼠标移入容器时停止滚动,移出时继续滚动。 曾想用的实现方法: 1.使用Marquee:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>打飞机</title> <style> #gamePanel{width:900px;height:500px;background:Black;position:absolute;left:100px;top:100px;} #gamePanel .score{font-size:12px;color:White;position:absolute;left:0;top:0;z-index:9999;} #gamePanel .bullet{width:5px;height:15px;position:absolute;background:url(img/bullet.png);overflow:hidden; _background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="img/bullet.png");} #gamePanel .flyer{width:48px;height:54px;position:absolute;background:url(img/flyer1.png); _background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="img/flyer1.png");} #gamePanel .enemy1{width:29px;height:32px;position:absolute;background:url(img/enemy1.png); _background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="img/enemy1.png");} #gamePanel .enemy2{width:26px;height:26px;position:absolute;background:url(img/enemy2.png); _background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="img/enemy2.png");} #gamePanel .enemy3{width:48px;height:48px;position:absolute;background:url(img/enemy3.png); _background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="img/enemy3.png");} #gamePanel .enemy4{width:48px;height:48px;position:absolute;background:url(img/enemy4.png); _background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="img/enemy4.png");} #gamePanel .bingo{width:18px;height:18px;position:absolute;background:url(img/bingo.png); _background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="img/bingo.png");} #gamePanel .change{width:40px;height:40px;position:absolute;background:url(img/change.png); _background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="img/change.png");} #startBtn{border-width:20px;border-style:solid;border-color:Black Black Black Green; po
------------------------------------盒子模型常用的八个属性--------------------------------- Js盒子模型 Js盒子模型指的是通过js提供的一系列的属性和方法,获取页面中元素的样式信息值 client系列(当前元素的私有属性) clientWidth/clientHeight:内容的宽度/高度+左右/上下填充,(和内容溢出没有关系) clientLeft:左边框的宽度(borderLeftWidth) clientTop:上
上篇文章有介绍一些小程序的自定义组件语法,这篇文章就不多做赘述,重点介绍组件的实现逻辑。
不知各位遇到特别长的图片时是怎么处理的? 是 截取符合长宽的部分做临时展示? 还是 硬要长宽100%模糊(啥也看不清)展示? 还是 先拿一个压缩的图片做占位,在鼠标移入或点击时放大预览?
在部分android机型上测试点击靠下的输入框时遇到弹出的软键盘挡住输入框问题,ios可自身弹起(ios自身的调整偶尔也会出问题,例如第三方键盘会遮挡,原因是第三方输入法的tool bar或者键盘也被当做可视区域,这里不做讨论)
今天在做页面UI改版的时候发现,我之前使用的是dom.scrollIntoView(); 使得点击右侧题目编号的时候,让左侧题目滚动到页面可视区域。
携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第12天,点击查看活动详情 >>
分享一个由原生JS实现的苹果菜单栏效果,效果如下: 实现的代码如下: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Ty
先放个图看看滑动固顶是啥效果: image.png 中间那个 tab 条,平常的时候是固定的,等到页面滑上去的时候,又像 fixed 一样贴在顶部。 position: sticky 就是用来实现这个效果的,元素不脱离文档流,仍然保留高度,所以这个属性真是人畜无害啊,而且效果如丝般润滑,堪比原生。 事实上,很多看起来人畜无害的东西,其背后都有一个大坑。 我们的 html 结构是这样的: <body ontouchstart=""> 06
随着技术不断更新与用户审美不断提升,一些App中/浏览器中的常用交互也在对用户更加友好,在某些数据展示较多页面或者导航栏页面,为了将栏目划分,使得视图模块更加明显,吸顶效果便在此背景下孕育而生。 那么,我们如何在web端来做一个吸顶效果呢?
这次的案例稍微有一点难度,在css和js上都需要多加思考,话不多说,让我们来开始吧~
获取页面中元素到文档区域document的横向、纵向坐标的两种方法及其比较 在js控制元素运动的过程中,对于页面元素坐标位置的获取是经常用到的,这里主要总结下两种方法:
功能介绍: 可以实现锁定表格的行和列的功能,效果和Excel里的冻结窗格类似,当然没有Excel那么强大了,只是类似。 问题: 当一个table太大而导致在屏幕里显示不下的时候,IE会出现滚动条,但是这时候就不好看了,对用户的操作也不是很方便。于是我们就想给他加一个限制,在制定的范围内滚动。 如何实现呢?网上也有不少实现方法了,效果如何就不发表意见了,这里主要是想说一下我的思路。 思路: 1、其实思路很简单,div有一个“功能”,给他的style 加上 "CLEAR: non
分享一个用原生JS实现的可拖拽照片墙,效果如下: 实现代码如下: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type"
想要实现图片持续滚动,既然使用js,就千万不要加css动画、过渡等相关样式,如果想要滚动的平滑一下,可以一像素一像素的感动,则很平滑,如果加了过渡动画,当图片重置为0时,会有往回倒的动画效果,跟预期不符。
给大家分享一个用原生JS实现拖拽元素时与另个一元素碰撞检测的小Demo,效果如下:
$("#tab-a-" + options.menuID).click(); // 选中打开的tab
•问题标注 Q:(question)•答案标注 R:(result)•注意事项标准:A:(attention matters)•详情描述标注:D:(detail info)•总结标注:S:(summary)•分析标注:Ana:(analysis)•提示标注:T:(tips)
分享一款基于js的图片排序效果。鼠标拖动图片,重新排列图片的排列顺序。该插件适用浏览器:IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗。效果图如下:
我们有时需要获得鼠标在某盒子中的位置,或者是随意移动某盒子的位置,在这些场景中我们可能经常需要用到clientWidth、offsetWidth、offsetTop啊等等。但是对于初学者来说(包括我),看到这些就头疼,因为感觉意思都相近,但作用却不同,所以今天天我就来捋一捋,搞清楚,后面好干活。好吧,废话不多说,开始吧。
我入职第二家公司接到的第一个需求就是修复之前外包做的滚动吸顶效果。我当时很纳闷为何一个滚动吸顶会有 bug,后来我查看代码才发现直接用的是 offsetTop 这个属性,而且并没有做兼容性处理。
随着Markdown越来越流行,Markdown编辑器也越来越多,除去所见即所得的实时预览编辑器外,通常其他Markdown编辑器都会采用源代码和预览双栏显示的方式,就像这样:
我们经常使用元素的width:100%和height:100%将元素的宽度和高度扩充至父元素的宽度和高度。但是前提是需要对其父元素显示设置宽度和高度,否则无效。
本文并非原创,只是真心觉得好,特别是图解的很到位,我在js中经常会用到,就记下来,与大家分享。
offsetWidth 和 offsetHight:获取元素的宽高 + padding + border,不包括margin。如下:
引用JS文件的代码: vardelta=0.15 varcollection; functionJavaScript
使用requestAnimationFrame代替setTimeout和setInterval:
一、飞机大战代码 1、今天我来分享一个飞机大战的代码,代码是用html+css+js写成的,还有一个img的文件夹,也就是放照片的,image文件夹链接放在下面。废话不多说代码在下面,大家自行观看!!! 2、 由于各种原因我们无法将image文件夹放在博文上,非常的抱歉!你们可以加我微信进群拿照片,我的微信号: y27724611159,大加加完好友之后我就把照片发个你们!!!真的不好意思 3、注意:请把放照片的文件夹务必命名为image !!!有兴趣的小伙伴们可以去http://haiyong.site
offset 翻译过来就是偏移量, 我们使用 offset系列相关属性可以动态的得到该元素的位置(偏移)、大小等。
别踩白板这个游戏相信大家都玩过,这个是基于HTML5打造的简单小游戏,在PC端和移动端都能够运行,适应多种平台,今天我们使用原生JS搭配JQuery构建这个小游戏--别踩白板。
定义游戏页面 通过HTML定义一个游戏页面。代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <meta http-equiv="content" content="text/html" charset="utf-8"/> <link rel="stylesh
在js中,offsetParent 属性表示最近的上级定位元素。要获取相对父级元素的位置,可以先判断 offsetParent 属性是否指向父元素,如果是,则直接使用 offsetLeft 和 offsetTop 属性获取元素相对于父元素的距离;否则分别获得当前元素和父元素距离窗口的坐标,然后求差。
2.创建一个制造烟花的构造函数,第一个参数为元素,第二参数为初始x轴位置,第三参数为y轴位置;
css3属性之多栏布局与JS实现瀑布流 背景:之前打算自己总结一下flex布局的知识点,发现自己无从下手,原因在何处:我反思了一下,其实原因很简单,使用的次数少,更多的时间使用了百分比,浮
实现一个通过触摸拖动操作来展开和收起底部悬浮框,并根据拖动过程中的位置和状态来调整底部容器的高度和展开状态的功能
我们这个项目使用webpack来打包构建,所以需要安装webpack的相关的一些依赖,把webpack和TypeScript等一些东西整合一下,以方便我们后面整个项目的开发。
在做网站开发的时候,经常会用到悬浮的侧边栏,让一些信息一直显示在当前的屏幕下,如联系方式与分享,下面给大家分享一个小Demo,实现效果如下:
分享一个用原生JS实现的特效导航条,效果如下: 实现代码如下: <!DOCTYPE html> <head> <meta charset="utf-8" /> <title>原生J
返回整个页面的滚动的位置,pageYOffset/pageXOffset 与 scrollY/scrollX 返回的值一致,前者是后者的别名,建议使用前者,不支持 IE8
imgfixed:元素的定位是相对于 window (或者 iframe)边界的,和其他元素没有关系。但是它具有破坏性,会导致其他元素位置的变化。
本文主要介绍一下什么是reflow,repaint, 怎样避免它们造成的不良影响, 怎么通过工具查看分析它们. 一.首先对浏览器渲染引擎下网页呈现过程简要说一下: 浏览器的渲染引擎开始解析html构建成DOM树,DOM树是以document对象为根节点,包含所有的html标签, 包括display: none隐藏的,也包括js动态添加的元素。 解析html的同时, 将css文件或者样式元素中的样式解析成CSS Rule Tree,解析时会去掉浏览器不能识别的样式。 根据DOM树和CSSOM来构造Ren
1.什么是懒加载? 懒加载也就是延迟加载。 当访问一个页面的时候,先把img元素或是其他元素的背景图片路径替换成一张大小为同一张图片的路径(这样就只需请求一次,俗称占位图),只有当图片出现在浏览器的可视区域内时,才设置图片正真的路径,让图片显示出来。这就是图片懒加载。 demo: //所有img元素的src属性值是同一个图片地址,自定义属性data-src里存储的是真正需要加载的图面地址,当图片出现在浏览器的可视区域内时,再把data-src的属性值赋值给对应的img元素的src属性 <ul cla
在我本地测试当中: 在IE、FireFox、Opera下都可以使用 document.body.clientWidth document.body.clientHeight 即可获得,很简单,很方便。 而在公司项目当中: Opera仍然使用 document.body.clientWidth document.body.clientHeight 可是IE和FireFox则使用 document.documentElement.clientWidth document.documentElement.clientHeight 原来是W3C的标准在作怪啊
希望能对Canvas绘制出来的图像进行点击、拖拽等操作,因为Canvas绘制出的图像能很好的美化。好像是想做炉石什么的游戏,我也没玩过。 Canvas在我的理解中就好像在一张画布上绘制图像,它只能看到却“摸”不到,那要如何进行操作呢。我不知道网上是怎么做的,这里用自己的想法做了个DEMO分享给大家。 思路: 虽然Canvas不能拖拽,但div可以拖拽,那怎么把二者结合起来呢。初步想法是将一个与Canvas图像大小差不多的div覆盖在其上,在拖拽div时将获取的光标坐标修正后传给Canvas绘制函数并刷新图像
在页面很长(超过3屏)且图片又很多时,默认情况下浏览器会加载所有图片,有可能导致第二屏的图片显示出来了,但第一屏的图片还在加载,这种情况最适合用"javascript延时加载"来改善用户体验. 原理: 1.根据图片元素距页面顶部的距离,判断图片自身在第几屏 2.所有图片元素的src值先不设置,改而用其它自定义属性,比如src写成lazy_src(这样浏览器就不会主动加载图片) 3.根据1的判断,如果轮到自己登场了(即到顶部的距离变化了,比如用户拉动滚动条了),则将lazy_src值赋值为src,这样浏览器就
领取专属 10元无门槛券
手把手带您无忧上云