我在socket.io和现代浏览器方面遇到了一些奇怪的问题.令人惊讶的是,IE9的工作正常,因为flashsocket的回退看起来效果更好.
在我的服务器(带快递)
var io = socketio.listen(server.listen(8080));
io.configure('production', function(){
console.log("Server in production mode");
io.enable('browser client minification'); // send minified client
io.enable('browser client etag'); // apply etag caching logic based on version number
io.enable('browser client gzip'); // gzip the file
io.set('log level', 1); // reduce logging
io.set('transports', [ // enable all transports (optional if you want flashsocket)
'websocket'
, 'flashsocket'
, 'htmlfile'
, 'xhr-polling'
, 'jsonp-polling'
]);
});
Run Code Online (Sandbox Code Playgroud)
在浏览器上,我可以在网络选项卡(在Chrome上)看到websocket已建立并101 Switching Protocols以待处理模式进入.之后,出现xhr-polling和jsonp-polling(flashsocket会发生什么?)
最糟糕的是,信息不会来回传播.我有这个连接:
io.sockets.on('connection', function (socket) {
// If someone new …Run Code Online (Sandbox Code Playgroud) 我有一个小的"pdf" - 观看者可以在iPad上使用.由于我发现用HTML格式化渲染PDF非常慢,所以我尝试使用PNG解决方案.由于它是一个webapp并且一切都是像素完美的,因此禁用了缩放.
我的想法是创建一种"窗口",实际上是一个封装图像的div,无论它有多大.到现在为止还挺好.
但是,我决定尝试使用Hammer来模仿pinchin pinchout并发生奇怪的事情.当你捏或捏时,页面似乎动摇,然后你无法做任何其他事情......但是,如果你在事件处理程序上添加一个警报(是的,一个警报),它会按预期工作.
这是代码:
(function($){
var pdfViewer = {
pdf: {},
currentPage : 1,
currentZoom : 200,
defaultZoom : 200,
intervalZoom : 30,
el : {
pdfWindow : $('.pdf-window'),
image : $('.pdf-window').find('img')
},
init : function(){
this.bindEvents();
},
bindEvents : function(){
var self = this;
this.el.pdfWindow.hammer().on('pinchin',function(e){
self.currentZoom = self.currentZoom - self.intervalZoom;
self.updateZoom.apply(self);
});
this.el.pdfWindow.hammer().on('pinchout',function(e){
self.currentZoom = self.currentZoom + self.intervalZoom;
self.updateZoom.apply(self);
});
},
updateZoom : function(){
this.el.image.attr('width',this.currentZoom + '%');
}
};
pdfViewer.init();
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
这是一个干净的演示.你应该试试iOS设备......任何可能出错的想法?
在尝试修复浏览器上某些幻灯片的一些问题时,我发现所有浏览器都可以正常工作,但 iOS 版 Safari 则不行。
令人惊讶的是,它不会在响应模式下的 Mac Safari 上发生,它只会发生在 iOS 上。
奇怪的行为是,一旦您到达页面底部,部分内容就会被覆盖。如果您在到达底部后再次滚动,则现在可以滚动。如果此时向上滚动,也会发生同样的情况。
可重现的最小测试用例:
html,
body,
main {
width: 100vw;
height: 100vh;
overflow: hidden;
}
#test {
height: 100vh;
overflow-x: hidden;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
}
p {
padding: 20px 0;
}
Run Code Online (Sandbox Code Playgroud)
标记是这样的:
<body>
<div id="test">
<p>Lots of p</p>
<p>Lots of p</p>
<p>Lots of p</p>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
具有可重现案例的 JSBin 是这样的。有谁知道这里发生了什么以及如何解决它?
我发现,由于某些原因,有利于的WebPack module而不是main上package.json.
我们有很多库在ES6中导出模块并且主要编译,但我们最终还是没有被编译的东西.采用几个着名的React模块,如React Bootstrap或React Toolbox
我可以看到我不会违反常规,但我很惊讶没有多少人碰到这个.如果SSR到位,React需要在浏览器和节点上运行,所以我不知道如何继续.
示例库在这里:https: //github.com/firstandthird/domodule/blob/master/package.json#L6
包括babel加载器上的node_modules和执行上述解决方案中指示的切换的两者似乎都违背了所有其他事情,这再次让我感到惊讶.
我发现只有部分解决方案是不排除node_modules,babel-loader但似乎它可能会让我反感.
这是Webpack配置的相关部分.
module.exports = config => ({
test: /\.m?js$/,
use: {
loader: 'babel-loader',
options: {
babelrc: false,
configFile: false,
presets: [
[
'@babel/preset-env',
{
targets: config.browserlist,
useBuiltIns: false,
modules: false,
exclude: ['transform-typeof-symbol']
}
]
],
cacheDirectory: true,
cacheCompression: config.minify,
compact: config.minify
}
}
});
Run Code Online (Sandbox Code Playgroud)
问题是,配置Webpack或我的库的正确方法是什么.我不介意改变所有的库,只要它是一个已知的标准或我们可能在这里丢失的东西.
我希望以下日期范围从65年前开始到18年前结束.相反,minDate编号将被忽略,并设置为结束日期之前的10年.无论我在minDate中作为值放置什么都没有区别.
$(function() {
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
minDate: "-65y",
maxDate: "-18y"
});
});?
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用该函数在 javascirpt 和 jQuery 中制作一个计时器setInterval。计时器应从 90 倒计时到零(秒)。
我为此使用的代码:
setInterval(settime(), 1000);
Run Code Online (Sandbox Code Playgroud)
在此settime()设置 var time(从 90 开始)-1,此操作必须每秒发生一次。我的问题是我不知道如何让这个动作发生 90 次;我尝试使用 for 循环,但计数器在 1 秒内从 90 计数到 0。
有谁知道更好的选择吗?
Vuex 的新手问题。可能做错了什么。我有这个简单的商店:
export default new Vuex.Store({
strict: process.env.NODE_ENV !== 'production',
state: {
items: []
},
getters: Object.assign({}, itemGetters),
mutations: Object.assign({}, itemMutations),
actions: Object.assign({}, itemActions),
});
Run Code Online (Sandbox Code Playgroud)
吸气剂是这样的:
export const itemGetters = {
allItems: state => state.items,
itemById: (state, getters) => id => getters.allItems.filter(s => s.id === id)[0],
};
Run Code Online (Sandbox Code Playgroud)
现在,我有这个视图,其中有一个嵌套视图。基本上是每个项目的信息模式。
如果我点击链接,我希望去查看填充了项目的元素模式。
export default {
name: 'Landing',
computed: {
items() {
return this.$store.getters.allItems;
}
},
created() {
if (this.items.length === 0) {
this.$store.dispatch('allItems');
}
}
};
Run Code Online (Sandbox Code Playgroud)
现在,输入该视图按预期工作,如果我单击嵌套视图,如下所示:
<template>
<div class="text">
<h1 class="heading">{{ item.title …Run Code Online (Sandbox Code Playgroud) 我有一个具有以下结构的数组:
$queues[n] Array (
[id] => integer
[idClient] => integer
[name] => string
[people] => integer )
Run Code Online (Sandbox Code Playgroud)
其中填充有:
$query = "SELECT clients.idClient AS 'idClient', queues.idQueue AS 'idQueue', queues.name AS 'name' FROM clients, queues WHERE clients.idClient = queues.client";
$queues = null;
$result = mysql_query($query);
if ($result){
while ($queue = mysql_fetch_assoc($result)){
$queues[] = array ("idClient" => $queue['idClient'], "id" => $queue['idQueue'], "name" => $queue['name'], "people" => 0);
}
}
Run Code Online (Sandbox Code Playgroud)
每个“n”值与数据库和人员中的队列匹配,默认设置为 0。
填充数组后,我再次将每个队列查询到其他表的数据库,以通过如下查询获取队列中的人数:
SELECT COUNT(*) FROM peoplequeued WHERE queue ='".$queue['name']."'
Run Code Online (Sandbox Code Playgroud)
进而:
$result = mysql_query($query); …Run Code Online (Sandbox Code Playgroud) 我通过cUrl收到一个用PHP生成的XML代码:
$c = curl_init("http://www.domain.com/script.php");
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$xmlstr = curl_exec($c);
Run Code Online (Sandbox Code Playgroud)
如果我回显$ xmlstr变量,它会显示以下内容:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<XGetPasoParadaREGResponse xmlns="http://tempuri.org/">
<XGetPasoParadaREGResult>
<PasoParada><cabecera>false</cabecera>
<e1>
<minutos>1</minutos>
<metros>272</metros>
<tipo>NORMAL</tipo>
</e1>
<e2>
<minutos>7</minutos>
<metros>1504</metros>
<tipo>NORMAL</tipo>
</e2><linea>28
</linea>
<parada>376</parada>
<ruta>PARQUE ALCOSA</ruta>
</PasoParada>
</XGetPasoParadaREGResult><status>1</status></XGetPasoParadaREGResponse>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
哪个是正确的,并且在脚本中生成的相同.但是,如果我尝试执行以下操作
$xml = simplexml_load_string($xmlstr);
if (!is_object($xml))
throw new Exception('Reading XML error',1001);
echo $xml->e1->minutos;
Run Code Online (Sandbox Code Playgroud)
不显示任何内容和print_r对象打印一个空对象.可能有什么不对?
我开始学习socket.io和node.js我正在尝试做一些非常基本的东西(或者我认为),但我无法做到.
这是我的节点应用程序:
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(8080);
var clients = [];
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
clients[socket.id] = true;
socket.broadcast.emit('conection', { id: clients});
});
Run Code Online (Sandbox Code Playgroud)
我想存储连接的客户端,然后onConnection将所有连接的客户端发送给它们.关键是,我不知道如何在JavaScript上正确使用数组,因为clients.push(socket.id)很好地使用函数然后,一旦客户端断开而没有循环通过数组,我将无法做到pop这一点socket.id,对吧?
即使有一种获取当前打开的套接字的方法,我也希望以这种方式实现它,因为我不会将该应用程序与当前套接字会话一起使用,而是使用其他东西.
我知道这是一个非常的菜鸟问题所以,拜托,请耐心:)