本帖最后由 plp626 于 2011-5-9 20:02 编辑
下面代码保存为test.html | <HTML> | | <BODY> | | <marquee scrollamount=10 width=200 behavior=scroll>bbs.bathome.net</marquee> <P> | | <marquee scrollamount=5 width=200 behavior=alternate>bbs.bathome.net</marquee> <P> | | <marquee scrollamount=15 width=200 behavior=slide>bbs.bathome.net</marquee> | | </BODY> | | </HTML>COPY |
现在用批处理分别实现上面scroll,alternate,slide三个效果:call:marquee "scrollamount=10 width=200 behavior=scroll" "bbs.bathome.net"COPY
call:marquee "scrollamount=5 width=200 behavior=alternate" "bbs.bathome.net"COPY
call:marquee "scrollamount=15 width=200 behavior=slide" "bbs.bathome.net"COPY 移动文字通用函数,要求代码短小者为佳。 | :marquee <"属性"> <"字符串"> | | | | goto:eofCOPY |
还有好多属性有待实现,比如: | <HTML> | | <BODY> | | <marquee scrollamount=5 width=400 direction=left>bbs.bathome.net</marquee> <P> | | <marquee scrollamount=10 width=400 direction=right>bbs.bathome.net</marquee> <P> | | <marquee scrollamount=15 width=400 direction=down>bbs.bathome.net</marquee> <P> | | <marquee scrollamount=20 width=400 direction=up>bbs.bathome.net</marquee> <P> | | </BODY> | | </HTML>COPY |
先看看大家的热情程度。
============================================
2011-5-9修订:
对于函数传递参数的格式不做硬性规定,
可以call:marquee "scrollamount=15 width=200 behavior=slide" "bbs.bathome.net"COPY 也可以 | ::主要是考虑到字符串作为值传递的很多缺陷,所以鼓励大家引用调用(将字符串保持在变量内,把变量名传递到函数体内) | | ::用逗号隔开属性值的方式,是考虑到cmd中set/a的特性,方便赋值。 | | set str=bbs.bathome.net | | call:marquee "scrollamount=15, width=200, behavior=slide" str COPY |
初衷是:让调用者觉得方便,同时又让函数的实现代码尽量简短(这个函数无需考虑效率问题)
============================================
看到大家有在函数内部求字符串长度的“操作”,我的观点是在参数传递时,可以把字符串的长度作为参数传递过去,这样可以保持marquee函数功能的单一,最大限度做到函数的复用。 | set Mystr=bbs.bathome.net | | call:strlen Mystr len | | call:marquee "scrollamount=10, width=200, behavior=slide" Mystr lenCOPY |
不用过于拘泥于上面的参数格式(上面的调用格式仅是我的做法),我主要看有没有更好的方式以及精简的代码
(大家还可以将三个效果用三个函数分别实现) |