- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嘿UX设计师在这里学习代码,请原谅我的无知和蹩脚的代码。
我有一个 CSS 动画类型覆盖了一个 Hero Image,它也应用了 JS 效果。
最初我无法同时渲染这两个图像。该类型会呈现,但您看不到其背后的主图,或者主图会出现但您看不到该类型。
起初我以为是某个类应用于在英雄图像上创建不透明背景的类型,但我通过有选择地注释掉一些东西来消除了这种可能性。
然后我意识到我需要将类型 div 放入 Hero Image div 中。我以前做过,但我又试了一次,结果成功了!但它起作用的原因是因为我刚刚有选择地注释掉了应用于英雄形象的 Javascript 效果。
所以问题一定是倾斜效果(javascript 效果)类。然而,我对 Javascript 知之甚少,所以我不确定是什么导致了这个问题。
我猜这与 javascript 处理页面内容的方式有关?我以前遇到过类似的问题,当时我有一个带有页脚的页面和一个由 JS 驱动的响应式图片库。 html 页脚将呈现,然后 JS 库将重新定位页面上的所有对象。所以我想这里可能会发生类似的事情,对吗?
这是代码的 JSFiddle:http://jsfiddle.net/thedonquixotic/8vv7t1as/2/
Tilt FX 是 JS 部分中的第二部分代码,为了便于查找,我已将其标记。
HTML相关部分如下:
<!--Hero image with tilt effect-->
<div class="hero">
<div class="hero__imgwrap">
<!--<div class="grid__item">
<a class="link link--kumya" href="About.html"><span data-letters="David French">David French</span></a>
</div>-->
<img class="hero__img tilt-effect" data-tilt-options='{ "opacity" : 0.3, "extraImgs" : 3, "movement": { "perspective" : 1700, "translateX" : -7, "translateY" : -7, "rotateX" : -7, "rotateY" : -7 } }' src="https://cdn.tutsplus.com/craft/uploads/2013/11/14-snowflakes-lay-paper-copy.jpg" alt="Welcome!" />
</div>
</div>
<!--Hero image with tilt effect-->
这里还有 Javascript:
/**
* tiltfx.js
* http://www.codrops.com
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright 2015, Codrops
* http://www.codrops.com
*/
;(function(window) {
'use strict';
/**
* **************************************************************************
* utils
* **************************************************************************
*/
// from https://gist.github.com/desandro/1866474
var lastTime = 0;
var prefixes = 'webkit moz ms o'.split(' ');
// get unprefixed rAF and cAF, if present
var requestAnimationFrame = window.requestAnimationFrame;
var cancelAnimationFrame = window.cancelAnimationFrame;
// loop through vendor prefixes and get prefixed rAF and cAF
var prefix;
for( var i = 0; i < prefixes.length; i++ ) {
if ( requestAnimationFrame && cancelAnimationFrame ) {
break;
}
prefix = prefixes[i];
requestAnimationFrame = requestAnimationFrame || window[ prefix + 'RequestAnimationFrame' ];
cancelAnimationFrame = cancelAnimationFrame || window[ prefix + 'CancelAnimationFrame' ] ||
window[ prefix + 'CancelRequestAnimationFrame' ];
}
// fallback to setTimeout and clearTimeout if either request/cancel is not supported
if ( !requestAnimationFrame || !cancelAnimationFrame ) {
requestAnimationFrame = function( callback, element ) {
var currTime = new Date().getTime();
var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
var id = window.setTimeout( function() {
callback( currTime + timeToCall );
}, timeToCall );
lastTime = currTime + timeToCall;
return id;
};
cancelAnimationFrame = function( id ) {
window.clearTimeout( id );
};
}
function extend( a, b ) {
for( var key in b ) {
if( b.hasOwnProperty( key ) ) {
a[key] = b[key];
}
}
return a;
}
// from http://www.quirksmode.org/js/events_properties.html#position
function getMousePos(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}
return {
x : posx,
y : posy
}
}
// from http://www.sberry.me/articles/javascript-event-throttling-debouncing
function throttle(fn, delay) {
var allowSample = true;
return function(e) {
if (allowSample) {
allowSample = false;
setTimeout(function() { allowSample = true; }, delay);
fn(e);
}
};
}
/***************************************************************************/
/**
* TiltFx fn
*/
function TiltFx(el, options) {
this.el = el;
this.options = extend( {}, this.options );
extend( this.options, options );
this._init();
this._initEvents();
}
/**
* TiltFx options.
*/
TiltFx.prototype.options = {
// number of extra image elements (div with background-image) to add to the DOM - min:1, max:5 (for a higher number, it's recommended to remove the transitions of .tilt__front in the stylesheet.
extraImgs : 2,
// the opacity value for all the image elements.
opacity : 0.7,
// by default the first layer does not move.
bgfixed : true,
// image element's movement configuration
movement : {
perspective : 1000, // perspective value
translateX : -10, // a relative movement of -10px to 10px on the x-axis (setting a negative value reverses the direction)
translateY : -10, // a relative movement of -10px to 10px on the y-axis
translateZ : 20, // a relative movement of -20px to 20px on the z-axis (perspective value must be set). Also, this specific translation is done when the mouse moves vertically.
rotateX : 2, // a relative rotation of -2deg to 2deg on the x-axis (perspective value must be set)
rotateY : 2, // a relative rotation of -2deg to 2deg on the y-axis (perspective value must be set)
rotateZ : 0 // z-axis rotation; by default there's no rotation on the z-axis (perspective value must be set)
}
}
/**
* Initialize: build the necessary structure for the image elements and replace it with the HTML img element.
*/
TiltFx.prototype._init = function() {
this.tiltWrapper = document.createElement('div');
this.tiltWrapper.className = 'tilt';
// main image element.
this.tiltImgBack = document.createElement('div');
this.tiltImgBack.className = 'tilt__back';
this.tiltImgBack.style.backgroundImage = 'url(' + this.el.src + ')';
this.tiltWrapper.appendChild(this.tiltImgBack);
// image elements limit.
if( this.options.extraImgs < 1 ) {
this.options.extraImgs = 1;
}
else if( this.options.extraImgs > 5 ) {
this.options.extraImgs = 5;
}
if( !this.options.movement.perspective ) {
this.options.movement.perspective = 0;
}
// add the extra image elements.
this.imgElems = [];
for(var i = 0; i < this.options.extraImgs; ++i) {
var el = document.createElement('div');
el.className = 'tilt__front';
el.style.backgroundImage = 'url(' + this.el.src + ')';
el.style.opacity = this.options.opacity;
this.tiltWrapper.appendChild(el);
this.imgElems.push(el);
}
if( !this.options.bgfixed ) {
this.imgElems.push(this.tiltImgBack);
++this.options.extraImgs;
}
// add it to the DOM and remove original img element.
this.el.parentNode.insertBefore(this.tiltWrapper, this.el);
this.el.parentNode.removeChild(this.el);
// tiltWrapper properties: width/height/left/top
this.view = { width : this.tiltWrapper.offsetWidth, height : this.tiltWrapper.offsetHeight };
};
/**
* Initialize the events on the main wrapper.
*/
TiltFx.prototype._initEvents = function() {
var self = this,
moveOpts = self.options.movement;
// mousemove event..
this.tiltWrapper.addEventListener('mousemove', function(ev) {
requestAnimationFrame(function() {
// mouse position relative to the document.
var mousepos = getMousePos(ev),
// document scrolls.
docScrolls = {left : document.body.scrollLeft + document.documentElement.scrollLeft, top : document.body.scrollTop + document.documentElement.scrollTop},
bounds = self.tiltWrapper.getBoundingClientRect(),
// mouse position relative to the main element (tiltWrapper).
relmousepos = {
x : mousepos.x - bounds.left - docScrolls.left,
y : mousepos.y - bounds.top - docScrolls.top
};
// configure the movement for each image element.
for(var i = 0, len = self.imgElems.length; i < len; ++i) {
var el = self.imgElems[i],
rotX = moveOpts.rotateX ? 2 * ((i+1)*moveOpts.rotateX/self.options.extraImgs) / self.view.height * relmousepos.y - ((i+1)*moveOpts.rotateX/self.options.extraImgs) : 0,
rotY = moveOpts.rotateY ? 2 * ((i+1)*moveOpts.rotateY/self.options.extraImgs) / self.view.width * relmousepos.x - ((i+1)*moveOpts.rotateY/self.options.extraImgs) : 0,
rotZ = moveOpts.rotateZ ? 2 * ((i+1)*moveOpts.rotateZ/self.options.extraImgs) / self.view.width * relmousepos.x - ((i+1)*moveOpts.rotateZ/self.options.extraImgs) : 0,
transX = moveOpts.translateX ? 2 * ((i+1)*moveOpts.translateX/self.options.extraImgs) / self.view.width * relmousepos.x - ((i+1)*moveOpts.translateX/self.options.extraImgs) : 0,
transY = moveOpts.translateY ? 2 * ((i+1)*moveOpts.translateY/self.options.extraImgs) / self.view.height * relmousepos.y - ((i+1)*moveOpts.translateY/self.options.extraImgs) : 0,
transZ = moveOpts.translateZ ? 2 * ((i+1)*moveOpts.translateZ/self.options.extraImgs) / self.view.height * relmousepos.y - ((i+1)*moveOpts.translateZ/self.options.extraImgs) : 0;
el.style.WebkitTransform = 'perspective(' + moveOpts.perspective + 'px) translate3d(' + transX + 'px,' + transY + 'px,' + transZ + 'px) rotate3d(1,0,0,' + rotX + 'deg) rotate3d(0,1,0,' + rotY + 'deg) rotate3d(0,0,1,' + rotZ + 'deg)';
el.style.transform = 'perspective(' + moveOpts.perspective + 'px) translate3d(' + transX + 'px,' + transY + 'px,' + transZ + 'px) rotate3d(1,0,0,' + rotX + 'deg) rotate3d(0,1,0,' + rotY + 'deg) rotate3d(0,0,1,' + rotZ + 'deg)';
}
});
});
// reset all when mouse leaves the main wrapper.
/*this.tiltWrapper.addEventListener('mouseleave', function(ev) {
setTimeout(function() {
for(var i = 0, len = self.imgElems.length; i < len; ++i) {
var el = self.imgElems[i];
el.style.WebkitTransform = 'perspective(' + moveOpts.perspective + 'px) translate3d(0,0,0) rotate3d(1,1,1,0deg)';
el.style.transform = 'perspective(' + moveOpts.perspective + 'px) translate3d(0,0,0) rotate3d(1,1,1,0deg)';
}
}, 60);
});*/
// window resize
window.addEventListener('resize', throttle(function(ev) {
// recalculate tiltWrapper properties: width/height/left/top
self.view = { width : self.tiltWrapper.offsetWidth, height : self.tiltWrapper.offsetHeight };
}, 50));
};
function init() {
// search for imgs with the class "tilt-effect"
[].slice.call(document.querySelectorAll('img.tilt-effect')).forEach(function(img) {
new TiltFx(img, JSON.parse(img.getAttribute('data-tilt-options')));
});
}
init();
window.TiltFx = TiltFx;
})(window);
最佳答案
我希望我能很好地理解它,所以我创建了一些修改CSS:
.grid__item {
position: absolute;
left: 50%;
z-index: 1;
display: flex;
justify-content: center;
top: 50%;
}
.link--kumya {
font-family: "Syncopate",sans-serif;
font-size: 6.5em;
overflow: hidden;
color: #242424;
position: relative;
left: -50%;
top: -70px;
text-align: center;
}
更改此部分后,会出现类型和动画背景
关于javascript - 附有 JS 效果的 CSS 动画类型阻塞/阻塞英雄图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30923679/
我正在关注 Angular 的 Tour of Heroes Tutorial我现在正在尝试将 observables 集成到我的项目中。将我的 hero.service.ts 文件更改为如下所示后
我正在关注 Angular 的 Tour of Heroes Tutorial我现在正在尝试将 observables 集成到我的项目中。将我的 hero.service.ts 文件更改为如下所示后
新一期王者荣耀登录礼包 免费领取三天皮肤+英雄 这是最新一期的活动 登录游戏即可获得共四次抽奖机会 有一定概率可中永久皮肤 经常玩游戏的可以领两天玩玩 活动地址:http://t.cn/A
我正在尝试制作一个网站,但我遇到了一个问题。我有一张图片,我需要它始终填满整个屏幕。就像他们在这个网站上所做的那样:http://mollyandmepecans.com这是我的网站:https://
我试图让 slider 上的图像在容器内全宽显示。我试过分离英雄文本 div,但它仍然不起作用。我多年来一直坚持这个,并意识到它可能是愚蠢的,所以堆栈溢出是我最后的选择。请参阅下面的代码和显示方式的图
我看过 Heroku 的 Taps 项目 ( http://devcenter.heroku.com/articles/taps )但是外键有很大的限制,所以我不太愿意使用它。 我想做的就是安全地获取
我正在运行 Angular 教程,但我无法理解某一部分实际发生的情况。我通过搜索找到了一些例子,但没有具体回答这个问题。这是代码: getHeroes (): Observable { retur
我正在运行 Angular 教程,但我无法理解某一部分实际发生的情况。我通过搜索找到了一些例子,但没有具体回答这个问题。这是代码: getHeroes (): Observable { retur
一位客户表示,他们非常喜欢 Google Play 处理他们的英雄 slider 的方式。我试过在 jQueryCycle 中复制效果,但无济于事。谁能阐明实现相同效果的最佳方法? 对于那些不熟悉的人
我正在做 Angular2 英雄之旅项目 https://angular.io/docs/ts/latest/tutorial/toh-pt2.html. {{hero.name}} 这里我可以使用下
我运行了 google page speed,它说我应该 Gzip 我的 javascript 文件? 我如何 gzip 我的 javascript 文件?如果有问题,我的网站托管在 heroku 上
前几天我将我的 Rails 4.1.7 应用程序发布到 Heroku 中,CSS 似乎工作正常。 但 javascript 文件部分响应。我有一个警报(“在 Charts-other.js 中”);
我不太熟悉 jQuery 和/或 JavaScript,但我正在尝试使用 Hero Slider对于我正在构建的网站。我几乎修改了代码来执行我想要的操作,但由于某种原因,第一张幻灯片似乎无法加载。奇怪
我正在学习着名的 Angular 教程,英雄之旅,但我正在努力迈出一步。 关于 sixth course, HTTP ,我们正在使用一种工具来模拟对 API 的 API 调用。 我想我遵循了所有步骤,
因此,我通常不会在将应用程序部署到 heroku 时遇到任何问题,但是,在这种特定情况下,我会遇到预编译失败错误... 这里的这一行对我来说很突出: remote: NoMethodEr
好吧,只是对这个发疯。 我在之前的 mx.datagrid 中使用了 rowcount 现在,使用“s:datagrid”,我尝试使用 requesteMaxRowCount 和 RequestMin
环境:Angular 5+ 来源:https://angular.io/tutorial 在 heroes.component.ts 类中有一个带冒号的赋值,如下所示: export class He
flask 应用程序可以在本地主机上正常登录和注册。但是当我把它推到 heroku 时,这就成了一个问题。它显示了上述错误。这是 app.py 代码 from flask import Flask,
我是一名优秀的程序员,十分优秀!