我试图检测移动设备上的方向变化,并在方向完成后触发功能,但功能内的代码在Android中不断触发,我不知道为什么.这是我的代码:
var supportsOrientationChange = "onorientationchange" in window;
var orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent,
function() { alert ('orientation changed'); },
false
);
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何写这个,以便它只在方向改变完成后触发一次?
我正在使用html5的拖放功能来重新排列屏幕上的dom元素 - 当我这样做时,我将css行为附加到拖放的各种状态,但我遇到的问题是悬停状态甚至在我之后仍然存在从DOM元素中拖出,删除和挖出.这是我的代码:
JAVASCRIPT:
function addDragListeners(){
$('.segmentListItem').each(function(index){
$(this)[0].addEventListener('dragstart',handleDragStart,false); //rollover for current
$(this)[0].addEventListener('drop',handleDrop,false); //drops dragged element
$(this)[0].addEventListener('dragover',handleDragOver,false); //allows us to drop
$(this)[0].addEventListener('dragenter',handleDragEnter,false); //rollover for target
$(this)[0].addEventListener('dragleave',handleDragLeave,false); //sets dragged item back to normal
$(this)[0].addEventListener('dragend',handleDragEnd,false); //sets all back to normal
});
}
function handleDragEnter(e) {
// this / e.target is the current hover target.
this.classList.add('over');
}
function handleDragLeave(e) {
this.classList.remove('over'); // this / e.target is previous target element.
}
function handleDragEnd(e){
$('.segmentListItem').removeClass('over'); //removes the over class on all elements
}
function handleDragStart(e){
draggedItem …Run Code Online (Sandbox Code Playgroud) 嗨我有一个包含这样的文本的列表项:
<li>Search</li>
Run Code Online (Sandbox Code Playgroud)
我想用字体真棒显示一个图标
li:before {
content: "\f002";
}
Run Code Online (Sandbox Code Playgroud)
我没有能力删除"搜索"文本(它是从Drupal CMS生成的,标记和类名称也是如此),但我想隐藏搜索文本,但显示伪元素(搜索图标).我该怎么做呢?通常,我要隐藏文本的方法就是:
li {
text-indent: -1000px;
overflow: hidden;
}
Run Code Online (Sandbox Code Playgroud)
但这也会隐藏伪元素
我目前正在使用jquery从codeigniter后端/ mySQL数据库通过ajax获取JSON数据,这很好.我遇到的问题是,与返回到jquery函数的数据一起,我还需要为另一个表中的某些数据运行PHP循环.目前我正在做的是等待第一个函数的ajax成功,然后对第二个函数进行另一个ajax调用 - 但我知道有一种方法可以用一个函数来完成它,我只是不确定如何.以下是两个数据库查询:
function get_selected_member($member = null){
if($member != NULL){
$this->db->where('id', $member); //conditions
}
$query = $this->db->get('members'); //db name
if($query->result()){
$member_result = $query->row();
return $member_result;
}
}
Run Code Online (Sandbox Code Playgroud)
和
function get_all_groups(){
$query = $this->db->get('groups');
$result = $query->result();
return $result;
}
Run Code Online (Sandbox Code Playgroud)
然后在javascript函数中,我正在做的是说:
var post_url = "/index.php/control_form/get_selected_member/" + selected_member_id;
$('#chosen_member').empty();
$.ajax({
type: "POST",
url: post_url,
success: function(member)
{
//Add all the member data and...
var post_url2 = "/index.php/control_form/get_all_groups/";
$.ajax({
type: "POST",
url: post_url2,
success: function(group)
{
//Create a dropdown of all the …Run Code Online (Sandbox Code Playgroud) 我想在方向改变时准确捕捉移动浏览器的窗口高度和宽度,但是(在Android中,我正在测试) - 当方向监听器触发并调用函数来捕获窗口的高度和宽度时,新尺寸还没有准确反映出来,所以我最终不得不拨打任意延迟来让事情记录下来.我该如何处理?这是我的代码:
window.addEventListener(orientationEvent, function() {
setTimeout("setViewport()", 500);
//setViewport();
}, false);
function setViewport() { //Called each time orientation changes, including initial orientation
viewportW = window.innerWidth; //only reports the accurate window size if the function is called on a delay
viewportH = window.innerHeight;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用threeJS,并且我已经安装了一个摄像头并查看场景的原点(0,0,0).我希望以一定的距离(半径)绕y轴移动相机,同时保持其对原点的聚焦,但我不确定如何设置方程式.目前,我只是旋转物体本身,但我想转动相机.这是移动网格的代码:
function checkRotation(){
if (keyboard.pressed("left")){
mesh.rotation.y += .05;
}
if (keyboard.pressed("right")){
mesh.rotation.y -= .05;
}
}
Run Code Online (Sandbox Code Playgroud)
这里有一些移动相机的例子:
camera.position.x = ??? (移动其x位置的某个方程式)camera.position.z = ??? (移动其z位置的一些方程式)camera.lookAt(mesh.position);
你能提供的任何帮助都会很棒.谢谢!
我的网站有一个网格系统,最初设置了一个应用于网格中每六个项目的样式
li:nth-child(5n+1){ margin-left:0 }
Run Code Online (Sandbox Code Playgroud)
我正在使我的网站响应,我有一个我指定的断点
li:nth-child(3n+1){ margin-left:0 }
Run Code Online (Sandbox Code Playgroud)
但问题是它仍在解释以前的5n + 1风格,这是我不想要的.如何告诉CSS忽略该样式.或者更好的是,我如何创建流体网格,以便每当li项目连续第一个时,它的边距为0,而其他所有项目的边距为25px?
我在这里操作 mapbox 标记半径示例:
https://www.mapbox.com/mapbox.js/example/v1.0.0/marker-radius-search/
尝试在随机点的特定半径内更改标记的颜色/图标,但尽管属性已注册为已更改,但颜色并未更改。这是我的代码:
clusterLayer = L.mapbox.featureLayer('examples.map-h61e8o8e').on('ready', function(e) {
clusterGroup = new L.MarkerClusterGroup({
showCoverageOnHover: false,
animateAddingMarkers: true
});
e.target.eachLayer(function(layer) {
clusterGroup.addLayer(layer);
layerArray.push(layer);
});
map.addLayer(clusterGroup);
});
window.setTimeout(eventFunction,eventTiming);
function eventFunction(){
clusterLayer.setFilter(affectMarker);
}
function affectMarker(feature) {
var fLat = feature.geometry.coordinates[1];
var fLng = feature.geometry.coordinates[0];
var fPt = L.latLng(fLat,fLng);
var dist = eventPt.distanceTo(fPt);
if (dist < eventRadius){
feature.properties['marker-color'] = eventColorNegative;
feature.properties['marker-symbol'] = 'danger';
}
}
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?我已经验证它正在返回有效积分。
另请注意,使用的标记是MakiMarkers
我正在尝试通过 AJAX 从本地主机上的谷歌云存储获取文件。我做了以下工作:
通过 gsutil 为我的存储桶设置 CORS:
gsutil cors set cors.json gs://my-project
cors.json 文件在哪里:
[
{
"origin": [
"*"
],
"responseHeader": ["Origin", "Accept", "X-Requested-With", "Authorization", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token"],
"method": [
"GET",
"OPTIONS"
],
"maxAgeSeconds": 1
}
]
Run Code Online (Sandbox Code Playgroud)
我已经验证过了 gsutil cors get gs://my-project
然后对于我公开的每个文件,在上传文件时都通过 node.js 客户端库:
bucket.file(object.name).makePublic()
通过控制台和 gsutil:
gsutil -m acl set -R -a public-read gs://my-project
然后在我的 ajax 请求中,我还发送标头:
$.ajax({
method: "GET",
url: "https://googleapis.com/storage/v1/b/my-project/o?delimiter=audio",
headers: {
'Access-Control-Allow-Origin': '*'
},
crossDomain: true,
}).done((data) => {
console.log(data)
})
Run Code Online (Sandbox Code Playgroud)
我仍然收到 cors 错误: …
ajax cross-domain cors google-cloud-storage google-cloud-platform
我正在使用React Transition Group来处理渲染组件时的动画 CSSTransitions。我想要一个组件的简单淡入。
转出似乎工作正常,但转入则不然。
如果我在属性上放置调试器onEnter,我可以看到转换实际上“应该”按预期工作。进入活动状态被触发,元素以 0.1 不透明度开始,如果我恢复调试器,就会发生转换。
但如果没有调试器,当组件渲染时,即使状态enter-active已添加到组件,它也只是立即可见 - 不会发生不透明度淡入。
这是我的代码:
<TransitionGroup component={null}>
{mobileSelectorsActive &&
<CSSTransition
classNames="anim_mobile_selectors"
timeout={5000}
//appear={true}
//mountOnEnter={true}
onEnter={()=>{
//debugger;
}}
>
<div>...</div>
</CSSTransition>
}
</TransitionGroup>
Run Code Online (Sandbox Code Playgroud)
和CSS:
.anim_mobile_selectors {
&-enter {
opacity: 0.1;
transition: opacity 5000ms linear;
}
&-enter-active, &-enter-done {
opacity:1;
}
&-exit {
opacity:1;
}
&-exit-active {
opacity: 0.1;
transition: opacity 5000ms linear;
}
}
Run Code Online (Sandbox Code Playgroud)
javascript animation css-animations reactjs react-transition-group
javascript ×6
jquery ×4
css ×3
ajax ×2
android ×2
mobile ×2
3d ×1
animation ×1
codeigniter ×1
cors ×1
cross-domain ×1
css3 ×1
fluid-layout ×1
hover ×1
mapbox ×1
math ×1
php ×1
reactjs ×1
three.js ×1