我正在尝试使用vanilla JavaScript和CSS创建一个垂直轮播.我知道jQuery有一个轮播库但是我想要从头开始构建这个没有外部库的东西.我开始尝试移动顶部图像,然后我计划继续进行下一个图像移动.我卡在第一张图片上.这是我需要你帮助的地方,StackOverflowers.
我的HTML:
<div class="slider vertical" >
<img class="first opened" src="http://malsup.github.io/images/beach1.jpg">
<img class="opened" src="http://malsup.github.io/images/beach2.jpg">
<img src="http://malsup.github.io/images/beach3.jpg">
<img src="http://malsup.github.io/images/beach4.jpg">
<img src="http://malsup.github.io/images/beach5.jpg">
<img src="http://malsup.github.io/images/beach9.jpg">
</div>
<div class="center">
<button id="prev">? Prev</button>
<button id="next">? Next</button>
</div>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
var next = document.getElementById('next');
var target = document.querySelector('.first');
next.addEventListener('click', nextImg, false);
function nextImg(){
if (target.classList.contains('opened')) {
target.classList.remove('opened');
target.classList.add('closed');
} else {
target.classList.remove('closed');
target.classList.add('opened');
}
}
Run Code Online (Sandbox Code Playgroud)
CSS:
div.vertical {
width: 100px;
}
.slider {
position: relative;
overflow: hidden;
height: 250px;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
-ms-box-sizing:border-box;
box-sizing:border-box;
-webkit-transition:-webkit-transform 1.3s ease;
-moz-transition: …Run Code Online (Sandbox Code Playgroud) 我一直在寻找一种计算JavaScript中最短路径的方法.我在https://github.com/loiane/javascript-datastructures-algorithms/tree/master/chapter09上一直在玩Groner的数据结构和算法(适当命名) .
我一直在寻找的麻烦是代码是如此定制的,几乎不可能重写以产生所需的结果.我希望能够获得从任何给定顶点到任何其他顶点的最短路径,而不是像Groner编码那样,只是来自A的所有内容的列表.我希望能够获得,例如,从F到B,或从C到A.
完整的代码在这里:http://jsfiddle.net/8cn7e2x8/
有人可以帮忙吗?
var graph = new Graph();
var myVertices = ['A','B','C','D','E','F'];
for (var i=0; i<myVertices.length; i++) {
graph.addVertex(myVertices[i]);
}
graph.addEdge('A', 'B');
graph.addEdge('B', 'C');
graph.addEdge('B', 'E');
graph.addEdge('C', 'D');
graph.addEdge('C', 'E');
graph.addEdge('C', 'G');
graph.addEdge('D', 'E');
graph.addEdge('E', 'F');
graph.dfs();
console.log('********* sortest path - BFS ***********');
var shortestPathA = graph.BFS(myVertices[0]);
//from A to all other vertices
var fromVertex = myVertices[0];
for (i = 1; i < myVertices.length; i++) {
var toVertex = myVertices[i],
path …Run Code Online (Sandbox Code Playgroud) 我的代码包含这个while循环:
while A.shape[0] > 0:
idx = A.score.values.argmax()
one_center = A.coordinate.iloc[idx]
# peak_centers and peak_scores are python lists
peak_centers.append(one_center)
peak_scores.append(A.score.iloc[idx])
# exclude the coordinates around the selected peak
A = A.loc[(A.coordinate <= one_center - exclusion) | (A.coordinate >= one_center + exclusion)]
Run Code Online (Sandbox Code Playgroud)
A是一只DataFrame看起来像这样的熊猫:
score coordinate
0 0.158 1
1 0.167 2
2 0.175 3
3 0.183 4
4 0.190 5
Run Code Online (Sandbox Code Playgroud)
我试图找到最大分数(一个峰值)A,然后在先前找到的峰值周围排除一些坐标(在这种情况下为几百个),然后找到下一个峰值,依此类推.
A这是一只非常大的熊猫DataFrame.在运行此while循环之前,ipython会话使用了20%的机器内存.我认为运行这个while循环只会导致内存消耗下降,因为我从中排除了一些数据DataFrame.但是,我观察到的是内存使用量不断增加,并且在某些时候机器内存耗尽.
我在这里错过了什么吗?我是否需要在某处明确释放内存?
这是一个可以使用随机数据复制行为的简短脚本:
import …Run Code Online (Sandbox Code Playgroud) 我正试图获得第n个工作日 - 例如,某个日期下降的第二个星期日.
例如,如果日期是2015年8月24日,我想这样做:
nthDayOfMonth(0, 2, new Date(2015, 7, 24))
Run Code Online (Sandbox Code Playgroud)
并获得2015年8月9日(8月的第2个星期日).然后,我希望能够添加一个月的日期,再次调用该功能,并获得2015年9月13日(9月的第2个星期日).
由于某种原因,下面的代码不起作用.
我错过了什么?
function nthDayOfMonth(day, n, date) {
console.log(day);
console.log(n);
var count = 0;
var idate = new Date(date);
idate.setDate(1);
while ((count) < n) {
idate.setDate(idate.getDate() + 1);
if (idate.getDay() == day) {
count++;
}
}
return idate;
Run Code Online (Sandbox Code Playgroud)
}
我有这个文字:
'BASE CÁL PREV SOC BASE CÁL 13º PREV SOC 01 672 1.653.806,08 18.512,98 1.667.621,57 2.647,38 07 23 12.965,11 0,00 12.965,11 0,00 13 5 10.517,81 0,00 10.517,81 0,00 TOTAIS: 700 1.677.289,00 18.512,98 1.691.104,49 2.647,38'
Run Code Online (Sandbox Code Playgroud)
不替换空格和断行的原始格式为:
NUMBER OTHER OTHER OTHER BASE CÁL PREV SOC BASE CÁL 13º PREV SOC
01 672 1.653.806,09 18.512,98 1.667.621,57 2.647,38
07 23 12.965,11 0,00 12.965,11 0,00
13 05 10.517,87 0,00 10.517,81 0,00
TOTAL: 700 1.677.289,00 18.512,98 1.691.104,49 2.647,38
Run Code Online (Sandbox Code Playgroud)
我想BASE CÁL PREV SOC仅在行01和07中提取列中的信息,但有时07不存在.第13行将被忽略.
所以我希望在一个正则表达式中有一个给定的短语和匹配的组.
需要明确的是,这些数据是在一个巨大的文本中,因此正则表达式不能是通用的.我必须明确传递一个接近数字的唯一短语.这里选择的短语是 …
我正在尝试动态调用返回不同类型的函数struct.
例如,让我们采用以下代码.
struct A {
Name string
Value int
}
struct B {
Name1 string
Name2 string
Value float
}
func doA() (A) {
// some code returning A
}
func doB() (B) {
// some code returning B
}
Run Code Online (Sandbox Code Playgroud)
我想将函数doA或doB作为参数传递给将执行函数和JSON编码结果的泛型函数.如下:
func Generic(w io.Writer, fn func() (interface {}) {
result := fn()
json.NewEncoder(w).Encode(result)
}
Run Code Online (Sandbox Code Playgroud)
但当我这样做时:
Generic(w, doA)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
cannot use doA (type func() (A)) as type func() (interface {})
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这种动态调用?
我有一个2D数组,存储与您在电话键盘上看到的不同的字母.
char [][] convert =
{ {},
{'A','B','C'},
{'D','E','F'},
{'G','H','I'},
{'J','K','L'},
{'M','N','O'},
{'P','R','S'},
{'T','U','V'},
{'W','X','Y'}
};
Run Code Online (Sandbox Code Playgroud)
如果我想找到一个5字母单词的所有可能的排列,从2D数组的前5行各取1个字母,我该怎么做?我正在考虑递归,但这只是让我感到困惑.
为了使这个问题更容易理解,这是一个例子:
一个3个字母的单词取自第1行{'A','B','C'}的第一个字母,第3行的第二个字母{'G','H','I'},以及第6行的第三个字母{'P','R','S'}.总共有27种可能的结果:AGP AGR AGS AHP AHR AHS AIP AIR AIS BGP BGR BGS BHP BHR BHS BIP BIR BIS CGP CGR CGS CHP CHR CHS CIP CIR CIS.
我的一个界面元素是使用HTML5 <canvas> 元素和相关的JavaScript API 呈现的.此元素在整个应用程序的同一屏幕和多个屏幕上的多个位置使用.什么是在所需的任何地方显示它的最有效方法?
我的第一个想法是绘制一个主画布,然后我将其克隆并插入页面中所需的位置.主画布可能类似于:
var master = $('<canvas>').attr({
width: 100,
height: 100
}),
c = master[0],
ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 150, 75);
Run Code Online (Sandbox Code Playgroud)
假设我想在这些div容器中复制画布:
<div class="square-container" id="square_header"></div>
...
<div class="square-container" id="square_dataTable"></div>
...
<div class="square-container" id="square_gallery"></div>
....
Run Code Online (Sandbox Code Playgroud)
当页面加载时,我将这样做以在每个容器中插入一个重复的canvas元素:
$(document).ready(function() {
$('.square-container').each(function() {
master.clone().appendTo($(this));
});
});
Run Code Online (Sandbox Code Playgroud)
在画布上呈现的内容将比本示例中使用的简单方块更复杂,但仍然只是一个静态图像.但是,有可能每页克隆数十个不同的图像数十次.
我想到的另一种方法是使用该toDataURL()方法创建一个图像,并将其设置为适当的图像源:
var master = $('<canvas>').attr({
width: 100,
height: 100
}),
c = master[0],
ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0,0,150,75);
var square = c.toDataURL('image/png');
Run Code Online (Sandbox Code Playgroud)
我会在必要时添加图片标签:
<img …Run Code Online (Sandbox Code Playgroud) 我开始学习Python,并在尝试从文件中读取值时遇到一些问题.
我的参数文件有点像这样:
var1 11111111
path_value "some/space containing path/file.txt"
var3 something
#some other values
var4 some/value1
var5 some/value2
var6 some/value3
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
file=open('this_file.txt')
for line in file:
fields = line.strip().split()
if(fields[0] in "var1"):
## this will give me 11111111
var_1_value=fields[1]
if(fields[0] in "path_value"):
## this will give me only till "/some/space
path_value_contains=fields[1]
Run Code Online (Sandbox Code Playgroud)
如何正确获取路径?我不确定这是一种有效的做事方式.你能告诉我任何更好的方法吗?
我没有使用任何模块.
我目前有一个显示不同团队数据的页面.
我有一些数据,用户可以点击这些数据使其处于"开启"或"关闭"状态,每个数据都显示不同的图标.它基本上就像一个清单,只是没有物理复选框.
我想记住哪些"复选框"已被勾选,即使用户刷新页面或关闭浏览器并稍后返回.
我听说这localStorage是一个不错的选择,但我不确定如何在像我这样的情况下使用它.
目前我有这个代码:
team1 = {
"information1": {
"name": "tom",
"age": "34"
},
"information2": {
"name": "bob",
"age": "20"
},
};
team2 = {
"information1": {
"name": "betsy",
"age": "27"
},
"information2": {
"name": "brian",
"age": "10"
},
};
$(document).ready(function() {
$("#displayObject1").on("click", function() {
switchData(team1);
});
$("#displayObject2").on("click", function() {
switchData(team2);
});
$("#table").on("click", ".on", function() {
$(this).removeClass("on");
$(this).addClass("off");
});
$("#table").on("click", ".off", function() {
$(this).addClass("on");
$(this).removeClass("off");
});
});
function switchData(object) {
$("#table").contents("div").remove();
if (!('rows' in object)) {
var …Run Code Online (Sandbox Code Playgroud)